img/home.png

Cache, predictor


Creating 1 byte cache, predicting the next character:

$DECLAREINT unpredicted one four zero mm i characters x prediction
$DIMENSION input[1499] output[1499]
$WEIGHTS commands=0
$PENVAL unpredicted 
$RESVAR unpredicted x characters input[]
$INVAR input[](73,116,32,119,97,115,32,109,97,110,121,32,97,110,100,32,109,97,110,121,32,97,32,121,101,97,114,32,97,103,111,44,13,73,110,32,97,32,107,105,110,103,100,111,109,32,98,121,32,116,104,101,32,115,101,97,44,13,84,104,97,116,32,97,32,109,97,105,100,101,110,32,116,104,101,114,101,32,108,105,118,101,100,32,119,104,111,109,32,121,111,117,32,109,97,121,32,107,110,111,119,13,66,121,32,116,104,101,32,110,97,109,101,32,111,102,32,65,110,110,97,98,101,108,32,76,101,101,59,13,65,110,100,32,116,104,105,115,32,109,97,105,100,101,110,32,115,104,101,32,108,105,118,101,100,32,119,105,116,104,32,110,111,32,111,116,104,101,114,32,116,104,111,117,103,104,116,13,84,104,97,110,32,116,111,32,108,111,118,101,32,97,110,100,32,98,101,32,108,111,118,101,100,32,98,121,32,109,101,46,13,13,73,32,119,97,115,32,97,32,99,104,105,108,100,32,97,110,100,32,115,104,101,32,119,97,115,32,97,32,99,104,105,108,100,44,13,73,110,32,116,104,105,115,32,107,105,110,103,100,111,109,32,98,121,32,116,104,101,32,115,101,97,58,13,66,117,116,32,119,101,32,108,111,118,101,100,32,119,105,116,104,32,97,32,108,111,118,101,32,116,104,97,116,32,119,97,115,32,109,111,114,101,32,116,104,97,110,32,108,111,118,101,45,45,13,73,32,97,110,100,32,109,121,32,65,110,110,97,98,101,108,32,76,101,101,59,13,87,105,116,104,32,97,32,108,111,118,101,32,116,104,97,116,32,116,104,101,32,119,105,110,103,101,100,32,115,101,114,97,112,104,115,32,111,102,32,104,101,97,118,101,110,13,67,111,118,101,116,101,100,32,104,101,114,32,97,110,100,32,109,101,46,13,65,110,100,32,116,104,105,115,32,119,97,115,32,116,104,101,32,114,101,97,115,111,110,32,116,104,97,116,44,32,108,111,110,103,32,97,103,111,44,13,73,110,32,116,104,105,115,32,107,105,110,103,100,111,109,32,98,121,32,116,104,101,32,115,101,97,44,13,65,32,119,105,110,100,32,98,108,101,119,32,111,117,116,32,111,102,32,97,32,99,108,111,117,100,44,32,99,104,105,108,108,105,110,103,13,77,121,32,98,101,97,117,116,105,102,117,108,32,65,110,110,97,98,101,108,32,76,101,101,59,13,83,111,32,116,104,97,116,32,104,101,114,32,104,105,103,104,45,98,111,114,110,32,107,105,110,115,109,97,110,32,99,97,109,101,13,65,110,100,32,98,111,114,101,32,104,101,114,32,97,119,97,121,32,102,114,111,109,32,109,101,44,13,84,111,32,115,104,117,116,32,104,101,114,32,117,112,32,105,110,32,97,32,115,101,112,117,108,99,104,114,101,13,73,110,32,116,104,105,115,32,107,105,110,103,100,111,109,32,98,121,32,116,104,101,32,115,101,97,46,13,13,84,104,101,32,97,110,103,101,108,115,44,32,110,111,116,32,104,97,108,102,32,115,111,32,104,97,112,112,121,32,105,110,32,104,101,97,118,101,110,44,13,87,101,110,116,32,111,110,32,101,110,118,121,105,110,103,32,104,101,114,32,97,110,100,32,109,101,45,45,13,89,101,115,33,45,45,116,104,97,116,32,119,97,115,32,116,104,101,32,114,101,97,115,111,110,32,40,97,115,32,97,108,108,32,109,101,110,32,107,110,111,119,44,13,73,110,32,116,104,105,115,32,107,105,110,103,100,111,109,32,98,121,32,116,104,101,32,115,101,97,41,13,84,104,97,116,32,116,104,101,32,119,105,110,100,32,99,97,109,101,32,111,117,116,32,111,102,32,116,104,101,32,99,108,111,117,100,32,98,121,32,110,105,103,104,116,44,13,67,104,105,108,108,105,110,103,32,97,110,100,32,107,105,108,108,105,110,103,32,109,121,32,65,110,110,97,98,101,108,32,76,101,101,46,13,13,66,117,116,32,111,117,114,32,108,111,118,101,32,105,116,32,119,97,115,32,115,116,114,111,110,103,101,114,32,98,121,32,102,97,114,32,116,104,97,110,32,116,104,101,32,108,111,118,101,13,79,102,32,116,104,111,115,101,32,119,104,111,32,119,101,114,101,32,111,108,100,101,114,32,116,104,97,110,32,119,101,45,45,13,79,102,32,109,97,110,121,32,102,97,114,32,119,105,115,101,114,32,116,104,97,110,32,119,101,45,45,13,65,110,100,32,110,101,105,116,104,101,114,32,116,104,101,32,97,110,103,101,108,115,32,105,110,32,104,101,97,118,101,110,32,97,98,111,118,101,44,13,78,111,114,32,116,104,101,32,100,101,109,111,110,115,32,100,111,119,110,32,117,110,100,101,114,32,116,104,101,32,115,101,97,44,13,67,97,110,32,101,118,101,114,32,100,105,115,115,101,118,101,114,32,109,121,32,115,111,117,108,32,102,114,111,109,32,116,104,101,32,115,111,117,108,13,79,102,32,116,104,101,32,98,101,97,117,116,105,102,117,108,32,65,110,110,97,98,101,108,32,76,101,101,46,13,13,70,111,114,32,116,104,101,32,109,111,111,110,32,110,101,118,101,114,32,98,101,97,109,115,44,32,119,105,116,104,111,117,116,32,98,114,105,110,103,105,110,103,32,109,101,32,100,114,101,97,109,115,13,79,102,32,116,104,101,32,98,101,97,117,116,105,102,117,108,32,65,110,110,97,98,101,108,32,76,101,101,59,13,65,110,100,32,116,104,101,32,115,116,97,114,115,32,110,101,118,101,114,32,114,105,115,101,44,32,98,117,116,32,73,32,102,101,101,108,32,116,104,101,32,98,114,105,103,104,116,32,101,121,101,115,13,79,102,32,116,104,101,32,98,101,97,117,116,105,102,117,108,32,65,110,110,97,98,101,108,32,76,101,101,59,13,65,110,100,32,115,111,44,32,97,108,108,32,116,104,101,32,110,105,103,104,116,45,116,105,100,101,44,32,73,32,108,105,101,32,100,111,119,110,32,98,121,32,116,104,101,32,115,105,100,101,13,79,102,32,109,121,32,100,97,114,108,105,110,103,45,45,109,121,32,100,97,114,108,105,110,103,45,45,109,121,32,108,105,102,101,32,97,110,100,32,109,121,32,98,114,105,100,101,44,13,73,110,32,116,104,101,32,115,101,112,117,108,99,104,114,101,32,116,104,101,114,101,32,98,121,32,116,104,101,32,115,101,97,44,13,73,110,32,104,101,114,32,116,111,109,98,32,98,121,32,116,104,101,32,115,111,117,110,100,105,110,103,32,115,101,97,46,13,13,65,110,110,97,98,101,108,32,76,101,101,13,13,0) characters (1499)
$RETVAR output[]
$MINIMIZE LINES 50

unpredicted=characters;                      // setting unpredicted to the number of characters
one=1;four=4;zero=0;
for (x=zero; x<characters; x++) {            // go through every character (of E. A. Poe's Annabel Lee)   
  mm=input[x];    
  if (mm==prediction) {unpredicted--;}       // decrease unpredicted ($PENVAL unpredicted ) it had been predicted right
  output[x]=input[x];                        // copy a character (its ASCII number) from input to output data
$BES
	                                     // HERE, a predicting algorithm should evolve.  
	                                     // In attempt to minimize the value of uncached, misspredicted characters                                          
	                                     // This is the area, where Evolution may take place and grow an embryo code.
$EES    
} 

After several hours, the following caching code has arisen. It has no more than 30 lines (as specified by $MINIMIZE LINES 50 metastatement; 20 lines of the initial frozen code and 30 newly developed lines). The predicting hit rate is 452 of 1499 characters. Not bad for 1 byte prediction and 30 lines. Allowing unlimited code size, all the poem (string) would migrate to some code.

$BES
    prediction=output[four];
    if (one>mm) {
        acritticall1=acritticall1+acritticall1;
        one=output[zero];
        four/=4;
    }
    if (one>prediction) {
        four=2;
    }
    acritticall1+=-11;
    prediction=output[four];
    if (prediction>=acritticall1) {
        four=one;
        acritticall1=0;
        prediction=output[acritticall1];
        if (one>mm) {
            goto labelcritticall14;
        }
        one+=-2;
    }
    if (one>acritticall1) {
        one+=-1;
        prediction=output[one];
        one=sqrt(acritticall1);
    }
    if (prediction>acritticall1) {
        one=output[zero];
        one+=4;
        if (one>mm) {
            one=output[zero];
        }
        four=one;
        one+=-1;
    }
    labelcritticall14:;
$EES    
} 




  And this is the result's result. Pinky characters have been successfully predicted.



It_was_many_and_many_a_year_ago,
In_a_kingdom_by_the_sea,
That
_a_maiden_there_lived_whom_you_may_know
By_
the_name_of_Annabel_Lee;
A
nd_this_maiden_she_lived_with_no_other_thought
Than
_to_love_and_be_loved_by_me.

I_was_a_child_and_she_was_a_child,
In_this_kingdom_by_the_sea:
But
_we_loved_with_a_love_that_was_more_than_love--
I_and_my_Annabel_Lee;
With
_a_love_that_the_winged_seraphs_of_heaven
Coveted
_her_and_me.
A
nd_this_was_the_reason_that,_long_ago,
In_this_kingdom_by_the_sea,
A_wi
nd_blew_out_of_a_cloud,_chilling
My
_beautiful_Annabel_Lee;
So
_that_her_high-born_kinsman_came
A
nd_bore_her_away_from_me,
To
_shut_her_up_in_a_sepulchre
In_this_kingdom_by_the_sea.

The
_angels,_not_half_so_happy_in_heaven,
Went
_on_envying_her_and_me--
Yes!--t
hat_was_the_reason_(as_all_men_know,
In_this_kingdom_by_the_sea)
That
_the_wind_came_out_of_the_cloud_by_night,
Chilling
_and_killing_my_Annabel_Lee.

But
_our_love_it_was_stronger_by_far_than_the_love
Of
_those_who_were_older_than_we--
Of
_many_far_wiser_than_we--
A
nd_neither_the_angels_in_heaven_above,
Nor
_the_demons_down_under_the_sea,
Ca
n_ever_dissever_my_soul_from_the_soul
Of
_the_beautiful_Annabel_Lee.

For
_the_moon_never_beams,_without_bringing_me_dreams
Of
_the_beautiful_Annabel_Lee;
A
nd_the_stars_never_rise,_but_I_feel_the_bright_eyes
Of
_the_beautiful_Annabel_Lee;
A
nd_so,_all_the_night-tide,_I_lie_down_by_the_side
Of
_my_darling--my_darling--my_life_and_my_bride,
In_the_sepulchre_there_by_the_sea,
In_her_tomb_by_the_sounding_sea.

A
nnabel_Lee