Jump to content
IGNORED

fbForth—TI Forth with File-based Block I/O [Post #1 UPDATED: 06/09/2023]


Lee Stewart

Recommended Posts

Actually, maybe it should not end with a ‘,’ because words that do, expect any numbers they consume to already be on the stack. If we call it NUMS , the following code will accomplish the task:

: NUMS   ( --- )
    BL WORD          ( get blank-delimited token from the input stream as a packed string to HERE)
    HERE NUMBER      ( convert packed string at HERE to a double number on stack)
    DO               ( stack should contain 0 on top and the 16-bit count of numbers coming)
        BL WORD      ( get next token to HERE)
        HERE NUMBER  ( convert to a double [32-bit] number)
        DROP ,       ( make it a single [16-bit] number and compile it into the dictionary)
    LOOP ;           ( get next number in input stream) 

This word expects a 16-bit count followed by count 16-bit numbers in the input stream. NUMS , count and count numbers must all be in the same block. If multiple blocks are required to compile all of the numbers, each block following the first must start with NUMS followed by the count of the numbers remaining to be loaded in that block followed by said numbers. Room must be available at the end of the block for --> to continue loading the next block as needed.

 

Using this word for loading the bulk of the code for the bitmap drawing of Alfred E. Neuman’s face (see the Bitmap Mode thread, posts #35 and #64) takes the loading of the blocks from over 4 minutes (246 seconds) down to 39 seconds (includes loading approximately 2100 numbers plus 2 blocks of definitions)! This code, including the definition of NUMS at the start, is in the following spoiler:

 

 

 

: NUMS BL WORD HERE NUMBER DO BL WORD HERE NUMBER DROP , LOOP ;
-27 VARIABLE LINES NUMS 255 -11 -23 -6 -28 -13 -22 -6 -20 -5
-12 -5 -27 -14 -26 -13 -38 -29 -42 -28 -40 -28 -50 -16 -8 13 0
13 -29 4 -29 9 -50 -17 -41 -28 -49 -17 -50 -8 -8 12 0 12 -28 5
-28 13 -50 -15 -49 -10 40 -26 42 -17 -4 9 -21 14 5 48 2 44 -53
-39 -45 -48 -55 -23 -55 -28 -61 -23 -58 -22 -42 -39 -43 -39 36
-52 36 -55 -37 -48 -32 -56 -32 -56 -26 -60 9 -74 33 -55 6 -12
12 -11 14 -8 24 -11 6 -13 10 -11 20 -9 10 -8 -23 -15 -24 -19
-26 -18 -22 -15 -25 -18 -22 -19 -23 -18 -21 -16 -49 2 -43 10 38
-11 43 -15 7 14 7 9 -9 13 -6 8 -5 -33 -4 -33 -6 -36 -6 -36 -5
-32 -5 -32 -7 -29 -7 -29 -39 -32 -38 -41 -62 -25 -54 -39 -50
-29 -50 -35 -54 -33 -57 -24 -38 -34 -39 -39 -51 -19 -60 -22 -57
-25 -50 -24 -48 -25 -46 -38 -42 -24 -42 -19 41 -26 43 -14 -3 7
-19 14 8 48 4 42 27 -38 31 -47 -29 -42 -16 -37 -11 -51 10 -48
26 -38 24 -47 -4 -73 14 -71 -3 -74 5 -74 5 -73 12 -72 8 -72 35
-57 -2 -48 5 -54 -15 -36 -20 -42 17 -34 32 -45 -6 -53 6 -48 -->

NUMS 283 40 -51 38 -43 39 -45 38 -50 38 -46 37 -53 37 -47 37
-46 15 -25 18 -24 23 -18 23 -20 12 -19 19 -18 8 -50 20 -49 -12
-53 -3 -62 -5 -49 14 -49 4 -62 16 -53 -41 -19 -41 -27 44 -14 43
-20 -22 13 -22 14 8 46 2 42 -40 -23 -39 -28 42 -26 50 -19 -23
14 -24 5 3 41 2 48 -51 -42 -39 -49 -47 -26 -49 -36 -53 -18 -59
-21 -45 -28 -53 -23 -40 -19 -37 -7 50 -18 50 -13 -25 5 -26 14 1
41 9 40 -22 -9 -19 -6 -21 -9 -18 -6 -21 -6 -11 -9 -19 -8 -16 -8
-57 -26 -57 -28 -37 -41 -37 -37 -59 -31 -50 -40 -39 -36 -36 -40
-5 -28 -6 -30 -6 -28 -7 -30 6 -28 5 -30 6 -29 6 -31 6 -37 9 -36
-12 -38 -2 -39 -6 -33 -2 -35 -13 -35 -8 -39 -20 -18 -17 -17 -14
-18 -15 -17 -17 -18 -16 -18 -20 -17 -14 -17 -39 -17 -35 -6 51
-14 48 -12 -24 8 -23 13 1 40 12 39 -36 -6 -36 -1 41 -14 40 -9
-23 8 -24 11 14 39 19 40 -26 34 -32 37 -32 37 -29 32 -29 32 -30
36 -29 32 -39 34 -35 -5 -35 -1 40 -13 41 -12 -26 7 -27 14 21 39
11 38 -61 -29 -56 -37 -47 -35 -42 -36 -49 -39 -45 -42 -61 -24
-59 -35 60 -24 55 -20 60 -23 61 -32 61 -29 61 -24 60 -29 59 -->

NUMS 286 -33 17 -53 5 -62 6 -48 17 -50 8 -48 2 -54 -28 -41 -18
-48 -14 -52 -4 -62 -5 -51 9 -51 -27 -43 -28 -47 -5 -62 8 -59
-46 14 -42 18 -45 25 -45 15 -42 18 -42 11 -43 11 -51 0 15 -19
18 -16 14 -16 18 -19 7 -18 8 -16 8 -17 11 -16 39 -42 38 -37 39
-40 40 -32 41 -33 40 -39 39 -34 39 -36 42 -40 43 -42 44 -42 45
-32 46 -36 45 -41 42 -38 43 -41 48 -11 47 7 41 -14 40 -9 15 37
15 36 17 36 19 36 -49 -28 -48 -37 -61 -32 -62 -27 -55 -35 -43
-49 -46 -34 -42 -35 -14 -65 -6 -71 14 -68 32 -57 18 -65 20 -63
14 -70 23 -65 31 -41 32 -43 3 -42 4 -43 -22 -43 -23 -42 -9 -52
-9 -52 30 -40 29 -45 14 -50 21 -48 -27 -46 -25 -46 -26 -47 -27
-47 -10 -10 -11 -15 -9 -11 -10 -15 -10 -13 -8 -13 -11 -11 -8
-12 21 -38 29 -44 -7 -48 -3 -48 -27 -45 -21 -47 -12 -55 -6 -61
48 6 49 -11 39 -10 41 -5 18 35 22 35 19 34 23 34 51 -3 45 8 40
-5 38 -11 23 35 43 17 45 17 27 33 46 -40 46 -36 43 -38 43 -39
46 -30 52 -33 47 -30 52 -32 57 -32 57 -27 44 -25 49 -21 7 -13
9 -8 10 -8 8 -12 23 -9 12 -7 11 -9 24 -10 57 -25 53 -24 52 -->

NUMS 285 -25 56 -24 56 -32 55 -26 56 -27 56 -29 52 -24 57 -26
-13 -13 -26 -17 -12 -16 -10 -18 -15 -14 -11 -18 -21 -14 -17 -14
18 -20 21 -17 12 -16 16 -19 8 -20 10 -19 13 -23 19 -23 -22 -22
-13 -21 -16 -22 -21 -23 -21 -21 -19 -23 -20 -21 -18 -21 47 4 49
-3 41 -4 37 2 46 16 41 16 41 16 47 9 37 4 41 -2 -49 -9 -48 -4
43 11 45 9 -2 11 1 11 -47 -4 -48 -9 -48 -3 -49 -1 2 11 8 8 4 11
9 9 46 -32 48 -28 49 -38 49 -35 50 -37 51 -25 51 -37 52 -30 -56
-23 -57 -29 -60 -24 -60 -33 -54 -23 -46 -29 -46 -40 -44 -42 -44
-34 -45 -38 -44 -37 -42 -37 -44 -38 -42 -38 -48 -46 -42 -49 21
-16 10 -18 22 -17 19 -25 20 -24 22 -19 10 -23 18 -25 -41 33 -35
34 -41 32 -38 32 -38 31 -42 31 -42 32 -45 30 -3 -36 -12 -37 7
-35 7 -35 -3 -37 -8 -36 -8 -38 -4 -38 8 -18 9 -16 -35 -45 -29
-58 -36 -46 -35 -53 -38 -48 -26 -57 -35 -48 -30 -58 -34 -52 -25
-59 -32 -55 -25 -60 -34 -49 -14 -68 -36 -51 -22 -61 -49 -3 -46
5 10 9 4 15 3 15 6 10 6 11 6 14 47 -22 52 -21 48 -21 56 -20 55
-21 48 -21 56 -20 59 -22 24 -64 32 -60 30 -59 34 -57 33 -59 -->

NUMS 295 35 -52 35 -56 36 -49 61 -32 42 -51 43 -51 51 -41 50
-41 45 -46 58 -37 54 -41 -39 30 -45 23 -38 30 -46 21 -46 24 -47
11 -46 12 -42 27 7 -29 6 -31 13 -35 13 -35 4 -37 8 -35 5 -36 8
-37 -16 -49 -8 -50 9 -53 9 -49 20 -37 29 -39 -17 -39 -24 -41 21
-36 32 -44 -2 -62 5 -61 9 -58 16 -53 -26 -44 -22 -46 -51 1 -43
12 7 14 15 13 13 11 17 8 20 10 27 4 -42 11 -49 2 8 13 19 12 19
11 10 12 22 9 27 5 -24 -56 -22 -59 -23 -58 -4 -74 -23 -56 -15
-67 -21 -57 -8 -72 -7 -73 -12 -69 -12 -68 -4 -71 -21 -58 -13
-68 -10 -71 8 -74 12 -32 14 -35 13 -32 12 -37 14 -34 13 -37 11
-37 14 -36 -17 -6 -10 -8 -13 -9 -10 -6 -10 -7 -11 -6 -12 -6 -15
-6 17 -35 21 -39 7 -62 14 -56 14 -51 -17 -48 4 -43 4 -47 -11
-12 -12 -14 -12 -13 -9 -15 -20 -16 -15 -16 -17 -16 -15 -16 -11
-22 -12 -24 -9 -22 -12 -23 -9 -20 -11 -24 -8 -20 -9 -23 -34 -2
-33 6 25 7 29 7 30 8 30 6 31 8 35 9 -33 3 -33 -1 33 8 36 8 36 7
36 2 35 4 35 7 -32 6 -31 11 -30 11 -29 4 3 48 -3 41 -5 41 2 48
-5 -59 -6 -62 12 -52 21 -47 -2 -54 -2 -53 -4 -60 3 -62 -44 -->

NUMS 301 -47 -41 -49 -54 -24 -56 -30 -36 -43 -37 -48 -47 -37
-49 -32 -40 -48 -45 -46 -38 -47 -35 -44 -58 -36 -51 -40 -58 -35
-48 -45 24 -42 32 -42 -3 -61 -3 -61 -54 -19 -50 -18 -5 -72 9
-72 10 -22 10 -22 19 -22 19 -22 13 -16 13 -16 9 -19 10 -20 -25
-42 -21 -41 2 -53 4 -54 29 -40 31 -46 26 -43 22 -48 6 -10 18 -6
14 -6 21 -7 22 -8 6 -11 1 -38 -14 -36 -13 -37 -11 -32 -14 -35
-12 -33 55 -37 41 -51 46 -48 61 -33 41 -49 37 -48 -10 -21 -10
-24 -28 -14 -22 -7 -3 43 -26 35 -26 35 -5 41 -9 39 -20 36 -26
34 -26 37 -6 -58 1 -60 -24 -43 -21 -42 3 -45 3 -46 4 -52 4 -53
72 73 72 63 71 74 70 78 71 62 70 58 69 57 65 53 70 78 65 83 64
83 58 86 64 53 55 48 56 49 43 49 47 48 55 48 58 86 46 86 42 84
46 85 44 50 39 52 42 50 39 51 41 85 40 85 39 86 33 86 38 51 33
48 35 79 35 58 34 79 34 58 34 57 32 56 34 80 32 79 32 85 30 83
31 83 31 80 30 82 30 79 31 55 29 55 33 49 23 49 32 48 25 48 24
50 22 50 28 55 17 78 18 79 20 79 20 80 20 84 21 51 18 48 19 50
17 48 16 48 14 48 17 49 14 49 19 85 11 86 13 48 12 53 12 48 -->

NUMS 298 11 53 11 54 15 57 15 58 14 59 14 59 -1 59 14 58 -2 58
10 85 7 83 6 84 1 86 0 86 -5 85 -6 84 -6 80 -7 83 -7 79 -5 79
-3 79 -2 78 -13 56 -14 56 -3 78 -2 59 -4 57 -4 56 -1 54 0 55 1
55 1 54 1 50 0 50 -1 48 -2 48 -7 48 -2 49 -6 49 -6 48 -9 51 -7
48 -10 50 -11 49 -17 49 -12 48 -16 48 -17 48 -21 51 -18 48 -22
50 -15 55 -16 55 -17 56 -22 78 -21 79 -19 79 -19 80 -19 84 -23
49 -30 49 -24 48 -30 48 -31 48 -31 55 -32 54 -32 49 -30 55 -28
55 -20 85 -25 86 -26 85 -29 83 -28 55 -32 70 -28 55 -31 71 -28
83 -33 86 -34 86 -37 86 -32 70 -41 49 -38 85 -40 84 -40 83 -40
81 -41 83 -41 79 -40 80 -37 78 -37 78 -41 65 -42 65 -38 78 -43
64 -48 78 -47 79 -45 79 -45 80 -45 84 -46 85 -51 86 -42 49 -47
49 -42 48 -48 48 -48 48 -56 70 -48 49 -56 71 -56 71 -60 56 -52
85 -54 84 -55 83 -59 85 -60 86 -64 86 -59 55 -58 54 -57 54 -55
55 -55 54 -55 50 -56 50 -57 48 -57 49 -61 49 -58 48 -60 48 -61
48 -64 51 -62 48 -65 50 -65 85 -67 84 -67 83 -67 79 -68 83 -68
79 -66 79 -64 79 -63 78 -68 56 -69 55 -64 78 -66 49 -72 49 -->

NUMS 84 -68 48 -73 48 -69 55 -73 55 -73 55 -73 48 -74 49 -74
54 61 71 61 65 60 73 60 63 59 73 59 72 60 65 58 60 59 61 54 56
59 74 55 78 59 75 54 80 54 80 48 80 46 79 55 79 54 56 48 56 47
57 46 57 47 78 46 78 45 78 45 58 7 76 11 66 10 66 6 76 9 66 1
66 0 66 6 75
BASE->R DECIMAL 120 CONSTANT XC 92 CONSTANT YC HEX
: AEN GRAPHICS2 4F DCOLOR ! F SCREEN
    LINES 1050 + LINES DO ( 4176 decimal)
        I @ XC +
        YC I 2+ @ -
        I 4 + @ XC +
        YC I 6 + @ -
        LINE
    8 +LOOP
    KEY DROP TEXT ;
R->BASE                      -->

BASE->R HEX
0 VARIABLE X 0 VARIABLE Y 0 VARIABLE X1 0 VARIABLE Y1
: AEN2 GRAPHICS2 4F DCOLOR ! F SCREEN
    LINES 1050 + LINES DO ( 4176 decimal)
        I @ XC + DUP X !
        YC I 2+ @ - DUP 1+ Y !
        I 4 + @ XC + DUP X1 !
        YC I 6 + @ - DUP 1+ Y1 !
        LINE
        X @ Y @ X1 @ Y1 @ LINE
    8 +LOOP
    KEY DROP TEXT ;     R->BASE   ;S

 

 

 

We can define a similar word for 8-bit numbers, say BYTES , that will compile a list of 8-bit numbers. The only change required is to replace the , before LOOP with C, .

 

If anyone has better ideas for names and/or code, let’s hear them.

 

...lee

Link to comment
Share on other sites

I think NUMS and BYTES is fine, but they should include a trailing colon as a reminder/indication that what follows is a not a collection of compiled literals but is instead a list of integers.

 

Consider:

: thing ( -- ) 5 NUMS 1 2 3 4 5 ;

NUMS looks like any other word in the dictionary. My assumption would be that it gets executed when thing is executed, and the integers 1 to 5 will be on stack. I'd question the empty stack comment, too ;-)

 

This (IMO!) looks more appropriate:

: thing ( -- ) 5 NUMS: 1 2 3 4 5 ;

To me, it's now clear that the numbers 1 2 3 4 & 5 are associated with NUMS: and are not simply a list of literals that are going to appear on the stack. I think it's standard Forth nomenclature to include a colon - I can't remember. There might be something in Thinking Forth (Brodie's second book) on the subject, or I've maybe read it in a Forth Dimensions article.

 

YMMV etc ;-)

Edited by Willsy
Link to comment
Share on other sites

As written, NUMS is not state-smart and would not work as intended in a definition. Also, because of the way I wrote NUMS , what you wrote should actually be

: thing ( -- ) NUMS 5 1 2 3 4 5 ;

As written, thing is a redefinition of NUMS that still expects a count and count numbers following it in the input stream. In addition to the functionality of NUMS , thing leaves 5, 1, 2, 3, 4 and 5 on the stack. I intend NUMS (or whatever we eventually call it) to compile a block of number tokens as numbers, which obviates the interpreter’s time-consuming dictionary search for each and every number token before it tries to convert each token to a number. NUMS is the antithesis of your DATA , i.e., it is execution-only, whereas DATA is compilation-only (at least, your instructions say it should only be used in a definition). Perhaps, I should make it check that the interpreter is in execution mode and throw an error if it is not.

 

...lee

Link to comment
Share on other sites

I tried including ?EXEC in the definition of NUMS per my last post; but, it did not work. The CFA for NUMS was dutifully compiled into the new word’s definition without a whimper! :-o I puzzled over that for a few minutes as I tried one other word that uses it that does work, viz., : , which is an immediate word. It would appear, then, that for ?EXEC to work the new word must also be declared IMMEDIATE !—otherwise, it never tries to execute during compilation so there is no point in including it. One defining word in fbForth and TI Forth that includes ?EXEC but is not declared IMMEDIATE is CODE —perhaps I should change that.

 

Unless someone like @Willsy disabuses me of the above conclusion, I need to augment the description in the manual for ?EXEC .

 

...lee

Link to comment
Share on other sites

Ah! My apologies: I just looked at the spoiler code in your above code and went "aaaaaaahhhhhhhhhhhhaaaaaaaaaaaa!"

 

Makes sense. I prefer it with a colon, but it's your dime ;)

 

Also, (nit-picking pedantry alert) if it's only to be used outside of a colon def, perhaps it should be called [NUMS] or, (wink) [NUMS:] in a similar convention to [COMPILE] and [iF] [ELSE] and [ENDIF] ?

Link to comment
Share on other sites

  • 3 weeks later...

What do you think of INTLIST: and BYTELIST: implemented as follows?

: INTLIST:   ( --- )   ( Input Stream:  count n1 ... ncount)
    ?EXEC            ( execution mode only!)
    BL WORD          ( get blank-delimited token from the input stream as a packed string to HERE)
    HERE NUMBER      ( convert packed string at HERE to a double number on stack)
    DO               ( stack should contain 0 on top and the 16-bit count of numbers coming)
        BL WORD      ( get next token to HERE)
        HERE NUMBER  ( convert to a double [32-bit] number)
        DROP ,       ( make it a single [16-bit] number and compile it into the dictionary)
    LOOP             ( get next number in input stream) 
;  IMMEDIATE	     ( declare word 'immediate' so ?EXEC works in compile mode)

: BYTELIST:   ( --- )   ( Input Stream:  count b1 ... bcount)
    ?EXEC            ( execution mode only!)
    BL WORD          ( get blank-delimited token from the input stream as a packed string to HERE)
    HERE NUMBER      ( convert packed string at HERE to a double number on stack)
    DO               ( stack should contain 0 on top and the 16-bit count of bytes coming)
        BL WORD      ( get next token to HERE)
        HERE NUMBER  ( convert to a double [32-bit] number)
        DROP C,      ( make it a single [16-bit] number and compile LSB into the dictionary)
    LOOP             ( get next number in input stream) 
;  IMMEDIATE	     ( declare word 'immediate' so ?EXEC works in compile mode)

I think these words are only useful after VARIABLE definitions as I used NUMS (now INTLIST: ) in drawing the Alfred E. Neuman graphic in the Bitmap Mode thread, posts #35 and #64.

 

...lee

Link to comment
Share on other sites

This might be a bit shorter? The high amount of identical code in the two routines caused me to stop and ponder...

 

(Not tested)

 

 

: (LIST:)   ( xt --- )   ( Input Stream:  count b1 ... bcount)
    ?EXEC            ( execution mode only!)
    BL WORD          ( get blank-delimited token from the input stream as a packed string to HERE)
    HERE NUMBER      ( convert packed string at HERE to a double number on stack)
    DO               ( stack should contain 0 on top and the 16-bit count of bytes coming)
        BL WORD      ( get next token to HERE)
        HERE NUMBER  ( convert to a double [32-bit] number)
        DROP         ( make it a single [16-bit] number)
        OVER EXECUTE ( execute either , or C, from the xt on the stack)
    LOOP             ( get next number in input stream)
; 

: INTLIST ( -- )
    ['] , (LIST:) ; IMMEDIATE         ( declare word 'immediate' so ?EXEC works in compile mode)
 
: BYTELIST ( -- )
    ['] C, (LIST:) ; IMMEDIATE         ( declare word 'immediate' so ?EXEC works in compile mode)
Edited by Willsy
Link to comment
Share on other sites

Cool! I was thinking of something similar, actually; but, I was too lazy. Your code for INTLIST and BYTELIST wiill need to be a bit different for fbForth:

: INTLIST ( -- )
    ' , CFA (LIST:) ; IMMEDIATE         ( declare word 'immediate' so ?EXEC works in compile mode)
 
: BYTELIST ( -- )
    ' C, CFA (LIST:) ; IMMEDIATE         ( declare word 'immediate' so ?EXEC works in compile mode)

because in TI Forth and fbForth there is no ['] and ' yields the PFA , not the CFA . I haven't tested it yet, either; but, it looks like it should work fine.

 

...lee

  • Like 1
Link to comment
Share on other sites

Yup. And, perhaps, add back the ':' at the end of the word definitions. And, hoist CFA into (LIST:) :

: (LIST:)   ( pfa --- )   ( Input Stream:  count b1 ... bcount)
    ?EXEC            ( execution mode only!)
    CFA              ( convert pfa of , or C, to its cfa for EXECUTE)
    BL WORD          ( get token from input stream as packed string to HERE)
    HERE NUMBER      ( convert packed string at HERE to double number on stack)
    DO               ( stack is 0 on top and 16-bit count of bytes coming)
        BL WORD      ( get next token to HERE)
        HERE NUMBER  ( convert to a double [32-bit] number)
        DROP         ( make it a single [16-bit] number)
        OVER EXECUTE ( execute either , or C, from the xt on the stack)
    LOOP             ( get next number in input stream)
    DROP             ( drop leftover execution token)
; 

: INTLIST: ( -- )   ( Input Stream: count b1 ... bcount)
    ' , (LIST:) 
; IMMEDIATE         ( declare word 'immediate' so ?EXEC works in compile mode)
 
: BYTELIST: ( -- )   ( Input Stream: count b1 ... bcount)
    ' C, (LIST:) 
; IMMEDIATE         ( declare word 'immediate' so ?EXEC works in compile mode)

...lee

Edited by Lee Stewart
  • Like 1
Link to comment
Share on other sites

  • 1 month later...
  • 3 weeks later...

I have been a little out of the loop lately because I got sidetracked on a path I had pursued a year and a half ago regarding whether the floating-point trigonometric functions (among others) in console GROM and those I was considering porting to TurboForth and, later, to fbForth (both of which I have done) from Geneve MDOS were the same (see TurboForth V1.2 (Beta)--Evolution & Arcana—post #35). I had chosen the ATN function as the one I would analyze. Of course, that required me to work through its GPL code in the console and compare it to the ALC of the MDOS library’s ATN function. ATN returns arctan x = φ, where x = tan φ. The way the calculation is done is via a truncation of the following Taylor series

post-29677-0-10066100-1427864850_thumb.gif

to

post-29677-0-09875800-1427866412.gif

I had noted that the coefficients used in the TI/99-4A and MDOS routines were close to but not exactly the same as the coefficients in the first equation above. I had suggested they had been “adjusted” to recover accuracy lost from truncating the above infinite series. My current detour was to try to discover how the adjustments had been made. I have pretty well determined how it was done and will bore you with the details in another post, soon.

 

Besides my curiosity, I have another reason for wanting to run this down, viz., I want to see whether I might be able to improve on any of the routines because I noticed that the SIN routine is slightly inaccurate under certain circumstances where I expected better results. Later... :sleep:

 

...lee

  • Like 1
Link to comment
Share on other sites

I may still have some letter traffic that went back and forth between us while I was doing the beta testing for the module, but I'm pretty sure that was in one of the boxes of stuff that was destroyed when the Turkish apartment I lived in in the late nineties flooded. . .

Link to comment
Share on other sites

I may still have some letter traffic that went back and forth between us while I was doing the beta testing for the module, but I'm pretty sure that was in one of the boxes of stuff that was destroyed when the Turkish apartment I lived in in the late nineties flooded. . .

 

Oh, my! :-o

 

...lee

Link to comment
Share on other sites

I had just moved in too--so almost everything was still in boxes. That was both good and bad. The bottom layer was generally damaged (bad) and all higher layers were nice and dry (good). Rainstorms and inadequate storm drains will get you every time. . .especially in Turkey, as the streets are the alternate storm drains when it rains heavily (I've had to wade through water that went well above the knees to cross a street more times than I can count). :rolling:

Link to comment
Share on other sites

Re my comment in post #966 about the TI-99/4A and Geneve-MDOS (ported to TurboForth and fbForth 2.0) implementations of the Taylor series for arctan x and sin x, I don’t think the coefficients were actually adjusted. Rather, I am nearly certain that high-precision tables of tangents and sines were fit to the relevant polynomials. I used a singular value decomposition (SVD) least squares polynomial fit from Numerical Recipes in C by Press et al. to tables of 1000 equidistant points for each trigonometric function. For the arctan function, the range for x was [0..tan π/8]. For the sine function, the range for x was [0..π/2], which was parameterized to [0..1] by dividing x by π/2, or more precisely, multiplying x by 2/π. The algorithms for the TI-99/4A (GPL/ALC console code) and Geneve’s MDOS (all ALC) are the same, i.e., the polynomials and there coefficients are identical.

 

Both the arctan polynomial and the sine polynomial are the same power series as far as the powers of x are concerned. They differ in the number of terms that converge to a usable value and, of course, the actual coefficients. The Taylor series differ only in the constant denominators, viz., the arctan series has 2k+1 for the denominator of the kth term and the sine series has (2k+1)! for the denominator of the kth term. This, however, does not matter for fitting actual data to the power terms (x, x3, x5, ... ) of an equation.

 

The SVD polynomial fit I mentioned above minimizes χ2 = Σ[yif(xi)]2, where yi = arctan xi or sin xi and f(xi) = calculated arctan xi or calculated sin xi . Stated another way, χ2 is the sum of the squares of the deviations of the calculated values from the actual values.

 

Once I fitted the data to the relevant equations, I rounded the coefficients to the maximum precision possible for TI-99/4A or Geneve MDOS, which is 13 0r 14 decimal digits, depending on the 7-digit radix-100 representation. The following table shows χ2 for the two trigonometric functions with the original 4A/MDOS equations and for my SVD fits:

 

    Function          χ2     Avg. Deviation

----------------- ---------- --------------

arctan (Original) 1.15x10-28    3.4x10-16

arctan (SVD fit)  1.81x10-29    1.3x10-16

 

sin (Original)    2.26x10-24    4.8x10-14

sin (SVD fit)     3.36x10-24    5.8x10-14

 

An average deviation can be obtained by dividing χ2 by the number of points (1000) and taking the square root of the result. That is the last column above. As you can see, the differences between the original TI/MDOS equations and my SVD fits are pretty much a wash. The average deviation above can be viewed as an approximation of the expected error in the algorithms involved. For arctan, this is beyond the last representable decimal digit—not too shabby. For sin, we’re talking about ±5 in the last representable decimal digit—not as good, but still not bad, if you ask me. It would probably be more instructive to plot the actual deviations to see whether the error gets worse for smaller values. I may do that before I move on to something else—I don’t know.

 

For now, here are all of the relevant coefficients rounded to the appropriate places:

             <-------------Arctan--------------> <-------------------Sin------------------->
Coefficients     TI/MDOS            SVD Fit            TI/MDOS               SVD Fit
------------ ----------------- ----------------- --------------------- ---------------------

     a0       1.000000000000    1.000000000000    1.570796326795        1.570796326795
     a1      -0.33333333333225 -0.33333333333191 -6.4596409750622 E-01 -6.4596409750622 E-01
     a2       0.19999999978996  0.19999999973044  7.969262624562 E-02   7.969262624558 E-02
     a3      -0.14285712697596 -0.14285712373243 -4.6817541310602 E-03 -4.6817541309646 E-03
     a4       0.11111049925053  0.11111041302514  1.604411684698 E-04   1.604411684986 E-04
     a5      -0.09089547919672 -0.09089419575135 -3.598809117031 E-06  -3.598809502671 E-06
     a6       0.07673712439164  0.07672589526873  5.688203332688 E-08   5.688251232470 E-08
     a7      -0.06506999940140 -0.06501272013244 -6.447316000000 E-10  -6.448060069683 E-10
     a8       0.05027913843885  0.05012174559119
     a9      -0.02535718798820 -0.02517750656165

 

...lee

  • Like 1
Link to comment
Share on other sites

Okay, but what simpletons like me want to know is: are the trig functions (now) accurate enough to plot a lander's course to Mars, and actually get it to the planet?

 

(by the way, brilliant Job, Lee. I actually understood some of it, too!) :thumbsup: :thumbsup: :thumbsup: :thumbsup:

Link to comment
Share on other sites

  • 1 month later...

Lee... I am planning to print out all 258 pages of the manual on card stock and comb bind it all with a clear plastic cover and black plastic back...

 

As long as you don't foresee any changes. ;)

 

Just waiting for my replacement black ink cartridge(s) to arrive (should be Monday) and I'll start printing up a storm. :)

 

When I get it done, I'll post a pic here.

 

Thanks again for all your hard work on this language...and the manual is simply fantastic.

 

 

For those of you who are interested in Forth, be sure to check out the May issue of SHIFT838... There might be a little bit of Forth stuff in it. ;)

Link to comment
Share on other sites

Lee... I am planning to print out all 258 pages of the manual on card stock and comb bind it all with a clear plastic cover and black plastic back...

 

As long as you don't foresee any changes. ;)

 

Just waiting for my replacement black ink cartridge(s) to arrive (should be Monday) and I'll start printing up a storm. :)

 

When I get it done, I'll post a pic here.

 

Thanks again for all your hard work on this language...and the manual is simply fantastic.

 

 

For those of you who are interested in Forth, be sure to check out the May issue of SHIFT838... There might be a little bit of Forth stuff in it. ;)

 

Thanks for your kind words.

 

I have actually made a handful of corrections of errors I have found. I was waiting to accumulate some more errata (they've gotta be there!) before posting an updated PDF, but I could do it sooner. I can't find the list of corrections right now, but a biggie was in Chapter 4. Sections 4.4 “Low Memory Expansion” and 4.5 “High Memory Expansion” were wrong—I did not change the information that changed from fbForth 1.0. I should also change the comment in the VDP Rollout Area (page 29) concerning transcendental functions because fbForth 2.0 does not use the console transcendental functions. I will try to post the updated manual by Monday. I will be on the road until next Wednesday or Thursday, so no promises.

 

...lee

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...