img/home.png

Functions


How to evolve a function from a table of values. Using Critticall. Here is how:

$DECLAREINT SSxx SSyy SSxy alien num1024 num0 tmp tmp1 tmp2 tmpi tmps distant xp yp i N
$DECLAREINT fx index funval
$DIMENSION X[10] Y[10]
$ENHANCING OFF
$PENVAL alien
$RESVAR X[] SSxx SSyy SSxy alien num1024 num0 tmp tmp1 tmp2 tmpi tmps distant xp yp i N
$SHOWVAR Y[] alien
                                    // !-----------------------------------------------------------------!
$WEIGHTS commands = 0               // !   We will consider any computing light weight. It is alien      !
                                    // !   variable, which is penalized here.                            !
                                    // !-----------------------------------------------------------------!
N=9;
num0=0;
fx=2;  X[index]=fx; index++;         // !-----------------------------------------------------------------!
fx=3;  X[index]=fx; index++;         // !                                                                 !
fx=5;  X[index]=fx; index++;         // !                                                                 !
fx=7;  X[index]=fx; index++;         // !                                                                 !
fx=11; X[index]=fx; index++;         // ! Initial values (primes in this case) set to X[] form 2 to 29.   !
fx=13; X[index]=fx; index++;         // !                                                                 !
fx=17; X[index]=fx; index++;         // !                                                                 !
fx=19; X[index]=fx; index++;         // !                                                                 !
fx=23; X[index]=fx; index++;         // !                                                                 !
fx=29; X[index]=fx;                  // !-----------------------------------------------------------------!
for (i=num0; i<=N; i++) {
    funval=i;                        // f(x)=x assumption
$BES
                                     // !-----------------------------------------------------------------!
                                     // !                                                                 !
                                     // !                                                                 !
                                     // ! Here, we hope, a function will evolve! Using X[] as an example. !
                                     // !                                                                 !
                                     // !                                                                 !
                                     // !-----------------------------------------------------------------!
$EES
    Y[i]=funval;                     // y=f(x) setting
}
Xp=0;                                // !-----------------------------------------------------------------!
Yp=0;                                // !                                                                 !
for (i=num0; i<=N; i++) {            // !                                                                 !
  tmp=X[i];                          // !                                                                 !
  Xp=Xp+tmp;                         // !                                                                 !
  tmp=Y[i];                          // !                                                                 !
  Yp=Yp+tmp;                         // !                                                                 !
}                                    // !                                                                 !
Xp=Xp/N;                             // !                                                                 !
Yp=Yp/N;                             // !                                                                 !
SSxx=0;                              // !                                                                 !
SSyy=0;                              // !                                                                 !
SSxy=0;                              // !                                                                 !
for (i=num0; i<=N; i++) {            // !                                                                 !
  //SSxx=SSxx+(X(i)-Xp)^2            // !                                                                 !
  tmp=X[i];                          // !                                                                 !
  tmp=tmp-Xp;                        // !                                                                 !
  tmp=tmp*tmp;                       // !   Correlation between X[], which is set at the beginning, and   !
  SSxx=SSxx+tmp;                     // !   Y[] which has to be calculated inside the (evolving)          !
                                     // !   $BES - $EES segment.                                          !
  //SSyy=SSyy+(Y(i)-Yp)^2            // !                                                                 !
  tmp=Y[i];                          // !                                                                 !
  tmp=tmp-Yp;                        // !                                                                 !
  tmp=tmp*tmp;                       // !                                                                 !
  SSyy=SSyy+tmp;                     // !                                                                 !
                                     // !                                                                 !
  //SSxy=SSxy+(X(i)-Xp)*(Y(i)-Yp)    // !                                                                 !
  tmp1=X[i];                         // !                                                                 !
  tmp1=tmp1-Xp;                      // !                                                                 !
  tmp2=Y[i];                         // !                                                                 !
  tmp2=tmp2-Yp;                      // !                                                                 !
  tmp=tmp1*tmp2;                     // !                                                                 !
  SSxy=SSxy+tmp;                     // !                                                                 !
}                                    // !                                                                 !
num1024=1024;                        // !                                                                 !
SSxx=sqrt(SSxx);                     // !                                                                 !
SSyy=sqrt(SSyy);                     // !                                                                 !
tmpi=SSxx*SSyy;                      // !                                                                 !
                                     // !                                                                 !
tmp1=SSxy/tmpi;                      // !                                                                 !
tmp1=tmp1*num1024;                   // !-----------------------------------------------------------------!
alien=num1024-tmp1;                  // More alien, if there is a small correlation.
distant=0;                           // !-----------------------------------------------------------------!
for (i=num0; i<=N; i++) {            // !                                                                 !
    tmp1=X[i];                       // !                                                                 !
    tmp2=Y[i];                       // ! Correlation may be perfect, but values still might be different.!
    if (tmp1!=tmp2) {                // ! Add that on the top of 1-r.                                     !
       distant++;                    // !                                                                 !
    }                                // !                                                                 !
}                                    // !-----------------------------------------------------------------!
alien=alien+distant;                 // How alien arrays X[] and Y[] are
alien=alien*num1024;                 // Just lift that some more





After an hour or so:


funval*=3; acritticall1=y[dummy]; funval=funval-acritticall1; if (dummy!=acritticall2) { acritticall1=-2; } acritticall2<<=4; y[dummy]=-acritticall1; funval|=1;

That is what we've got! It's 100% correct, regarding given numbers, of course.