feat(v4): Phase 7 Task 4 -- v3's entropy, TOP-WORDS, WORD-ENTROPY and (- words (#189)
capsules/v4/physics.4th, blocks 8202-8204: ENTROPY@ ENTROPY! RESET-ENTROPY as kernel requests -35..-37 (a word's heat by the address ' leaves, a data word's too; an error for what is not a word, as v3's); TOP-WORDS and WORD-ENTROPY in StarForth, printing in v3's form what the kernel gives them through (HOT#) (HOT) (XT-HEAT), -38..-40 (the i-th hottest in v3's stable order); (- in StarForth, skipping to the matching close paren with nesting, as v3's code does. Tests first: test_mesh_boot.c 101 checks, 110 on, 98 without opcode physics. Listing: 403 live words. amd64 PASS, word_count=403. Not pushed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
This commit is contained in:
@@ -277,6 +277,33 @@ int main(void)
|
||||
}
|
||||
r = line(V4_MESH_HERA, "INFER-RUN INFER-WINDOW@ . INFER-DECAY@ Q.TO-INT . INFER-VARIANCE@ Q.TO-INT . INFER-FIT@ Q.TO-INT . INFER-EARLY-EXIT@ .", &how);
|
||||
CHECK(how == V4_TEXT_COMPLETED && strstr(r, "ERROR") == 0, "INFER-RUN and its five readings, with no error: \"%s\"", r);
|
||||
/* v3's StarForth module: the entropy words (a word's execution heat, by the address ' leaves), TOP-WORDS,
|
||||
* WORD-ENTROPY, (- */
|
||||
r = line(V4_MESH_HERA, ": NEWWORD ; ' NEWWORD ENTROPY@ .", &how);
|
||||
CHECK(strcmp(r, "0 ") == 0, "ENTROPY@ of an unused word: 0 (\"%s\")", r);
|
||||
r = line(V4_MESH_HERA, ": ENTTEST 1 DROP ; : E3 ENTTEST ENTTEST ENTTEST ; E3 ' ENTTEST ENTROPY@ .", &how);
|
||||
CHECK(strcmp(r, "3 ") == 0, "ENTROPY@ counts each call (\"%s\")", r);
|
||||
r = line(V4_MESH_HERA, ": ENTSET ; 42 ' ENTSET ENTROPY! ' ENTSET ENTROPY@ . 10 ' ENTSET ENTROPY! 20 ' ENTSET ENTROPY! ' ENTSET ENTROPY@ .", &how);
|
||||
CHECK(strcmp(r, "42 20 ") == 0, "ENTROPY! sets it, and again (\"%s\")", r);
|
||||
r = line(V4_MESH_HERA, "0 ENTROPY@", &how);
|
||||
CHECK(how == V4_TEXT_ERROR, "ENTROPY@ of what is not a word is an error, as v3's (%d \"%s\")", how, r);
|
||||
r = line(V4_MESH_HERA, "42 0 ENTROPY!", &how);
|
||||
CHECK(how == V4_TEXT_ERROR, "and ENTROPY! (%d)", how);
|
||||
r = line(V4_MESH_HERA, "-5 TOP-WORDS", &how);
|
||||
CHECK(how == V4_TEXT_COMPLETED && strcmp(r, "TOP-WORDS: invalid count -5\n") == 0, "TOP-WORDS of -5: v3's message (\"%s\")", r);
|
||||
r = line(V4_MESH_HERA, "900000000 ' ENTSET ENTROPY! 899999999 ' ENTTEST ENTROPY! 2 TOP-WORDS", &how);
|
||||
CHECK(how == V4_TEXT_COMPLETED && strcmp(r, "Top 2 most frequently used words:\n==================================\n1. ENTSET: 900000000\n2. ENTTEST: 899999999\n") == 0,
|
||||
"TOP-WORDS 2: the two hottest, in v3's form (\"%s\")", r);
|
||||
r = line(V4_MESH_HERA, "WORD-ENTROPY", &how);
|
||||
CHECK(how == V4_TEXT_COMPLETED && strstr(r, "Word Usage Statistics (Execution Heat Counts):\n") == r
|
||||
&& strstr(r, "ENTSET: 900000000\n") && strstr(r, "Total executions: ") && strstr(r, "Total words: "),
|
||||
"WORD-ENTROPY: v3's report (\"%.120s...\")", r);
|
||||
r = line(V4_MESH_HERA, "RESET-ENTROPY ' ENTSET ENTROPY@ . ' ENTTEST ENTROPY@ .", &how);
|
||||
CHECK(strcmp(r, "0 0 ") == 0, "RESET-ENTROPY: every word's heat back to 0 (\"%s\")", r);
|
||||
r = line(V4_MESH_HERA, "1 (- comment here ( nested ) still ) 2 + .", &how);
|
||||
CHECK(strcmp(r, "3 ") == 0, "(- skips to its ), nesting as v3's code does (\"%s\")", r);
|
||||
r = line(V4_MESH_HERA, "DEPTH (- comment ) DEPTH SWAP - .", &how);
|
||||
CHECK(strcmp(r, "1 ") == 0, "and touches no stack: the second DEPTH sees only the first's (\"%s\")", r);
|
||||
r = line(V4_MESH_HERA, "FORGET FT1", &how);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user