Without further ado, I present you my TriINTERCAL system library, which is almost complete.
(1000) PLEASE IGNORE .4 PLEASE ABSTAIN FROM (1005) (1009) DO STASH .1 + .2 + .5 + .6 DO .4 <- #1 DO (1004) NEXT (1004) PLEASE FORGET #1 DO .3 <- '^.1$.2'~'#0$#29524' DO .6 <- "'&"'^"'&"'^"'&.1$.2'~'#0$#29524'"$#29524'~'#0$#29524'"$#59048' ~'#0$#29524'"$#29524'~'#0$#29524'"$#59048'~'#0$#29524'" PLEASE DO .5 <- "V!6~#19683'$#1"~#1 DO (1002) NEXT DO .4 <- #2 (1005) DO (1006) NEXT (1999) DOUBLE OR SINGLE PRECISION OVERFLOW (1002) DO (1001) NEXT (1006) PLEASE FORGET #1 PLEASE DO .5 <- "V'".6~.6"~#1'$#1"~#1 DO (1003) NEXT DO .1 <- .3 DO .2 <- "!6$#0'~'#9841$#2'"~#59048 DO .2 <- '^.2$.2'~'#0$#29524' DO (1004) NEXT (1003) DO (1001) NEXT DO REINSTATE (1005) (1007) PLEASE RETRIEVE .1 + .2 + .5 + .6 DO REMEMBER .4 PLEASE RESUME #2 (1001) DO RESUME .5 (1010) DO STASH .1 + .2 + .4 DO .4 <- .1 DO .1 <- '?#59048$.2'~'#0$#29524' DO (1020) NEXT PLEASE DO .2 <- .4 PLEASE DO (1009) NEXT DO RETRIEVE .1 + .2 + .4 PLEASE RESUME #1 (1020) DO STASH .2 + .3 DO .2 <- #1 PLEASE DO (1021) NEXT (1021) DO FORGET #1 DO .3 <- "V!1~.2'$#1"~#1 PLEASE DO .1 <- '^.1$.2'~'#0$#29524' DO (1022) NEXT DO .2 <- !2$#0'~'#9841$#1' DO (1021) NEXT (1023) PLEASE RESUME .3 (1022) DO (1023) NEXT PLEASE RETRIEVE .2 + .3 PLEASE RESUME #2 (1030) DO ABSTAIN FROM (1033) PLEASE ABSTAIN FROM (1032) (1039) DO STASH :1 + .5 DO (1530) NEXT DO .3 <- :1~#29524 PLEASE DO .5 <- :1~'#29403$#29403' DO .5 <- 'V"!5~.5'~#2"$#1'~#1 DO (1031) NEXT (1032) DO (1033) NEXT DO (1999) NEXT (1031) DO (1001) NEXT (1033) DO .4 <- .5 DO REINSTATE (1032) PLEASE REINSTATE (1033) DO RETRIEVE :1 + .5 PLEASE RESUME #2 (1060) DO .3<-'V".1$.2"'~'#0$#29524' DO RESUME #1 (1070) DO .3<-'&".1$.2"'~'#0$#29524' DO RESUME #1 (1080) DO .3<-'?".1$.2"'~'#0$#29524' DO RESUME #1 (1090) DO .3<-'^".1$.2"'~'#0$#29524' DO RESUME #1 (1091) DO .3<-'@".1$.2"'~'#0$#29524' DO RESUME #1 (1500) PLEASE ABSTAIN FROM (1502) PLEASE ABSTAIN FROM (1506) (1509) PLEASE STASH :1 + .1 + .2 + .3 + .4 + .5 + .6 DO .1 <- :1~#29524 PLEASE DO .2 <- :2~#29524 DO (1009) NEXT DO .5 <- .3 PLEASE DO .6 <- .4 DO .1 <- :1~'#29403$#29403' DO .2 <- :2~'#29403$#29403' DO (1009) NEXT DO .1 <- .3 PLEASE DO (1503) NEXT DO .6 <- .4 DO .2 <- #1 DO (1009) NEXT DO .1 <- .3 DO (1501) NEXT (1504) PLEASE RESUME .6 (1503) DO (1504) NEXT (1501) DO .2 <- .5 DO .5 <- "V.6$.4"~#1 DO (1505) NEXT (1506) DO (1502) NEXT PLEASE DO (1999) NEXT (1505) DO (1001) NEXT (1502) DO :4 <- .5 DO (1520) NEXT DO :3 <- :1 PLEASE RETRIEVE :1 + .1 + .2 + .3 + .4 + .5 + .6 DO REINSTATE (1502) DO REINSTATE (1506) PLEASE RESUME #3 (1510) DO STASH :1 + :2 + :4 DO :1 <- "'?":2~'#29524$#0'"$#59048'~'#0$#29524'"$"'?":2~'#0$#29524'"$#59048'~'#0$#29524'" DO :2 <- #1 DO (1509) NEXT PLEASE RETRIEVE :1 DO :2 <- :3 PLEASE DO (1509) NEXT DO RETRIEVE :2 + :4 PLEASE RESUME #1 (1520) PLEASE STASH .3 + .4 DO .3 <- .1~#22143 DO (1525) NEXT PLEASE DO .4 <- 'V.3$".2~#22143"'~'#0$#29524' DO .3 <- .1~#7381 PLEASE DO (1525) NEXT DO :1 <- .4$"'V.3$".2~#7381"'~'#0$#29524'" PLEASE RETRIEVE .3 + .4 DO RESUME #1 (1525) DO .3 <- !3$#0'~'#121$#242' DO RESUME #1 (1530) DO STASH :2 + :3 + .3 + .5 DO :1 <- #0 DO :2 <- .2 DO .3 <- #1 DO (1535) NEXT (1535) PLEASE FORGET #1 DO .5 <- "@'"^!1~.3'$#7"~#4'$#2"~#10 DO (1531) NEXT PLEASE DO (1500) NEXT DO :1 <- :3 DO (1500) NEXT DO :1 <- :3 PLEASE DO (1533) NEXT (1531) DO (1534) NEXT DO (1500) NEXT DO :1 <- :3 DO FORGET #1 DO (1533) NEXT (1534) PLEASE DO (1001) NEXT DO FORGET #1 (1533) DO FORGET #1 DO .3 <- !3$#0'~'#9841$#1' DO :2 <- ":2~'#0$#29524'"$"'":2~'#9841$#0'"$#0'~'#9841$#1'" PLEASE DO .5 <- "V'".3~.3"~#2'$#1"~#1 DO (1532) NEXT DO (1535) NEXT (1532) DO (1001) NEXT PLEASE RETRIEVE :2 + :3 + .3 + .5 DO RESUME #2 (1540) PLEASE ABSTAIN FROM (1541) DO ABSTAIN FROM (1542) (1549) PLEASE STASH :1 + :2 + :4 + :5 + .1 + .2 + .5 + .6 DO .1 <- :1~#29524 PLEASE DO .2 <- :2~'#29403$#29403' DO .5 <- :1~'#29403$#29403' DO (1530) NEXT DO :3 <- :1 DO .2 <- :2~#29524 PLEASE DO (1530) NEXT DO :5 <- :1 DO .1 <- .5 DO (1530) NEXT DO :4 <- :1 PLEASE DO :1 <- ":3~'#29403$#29403'"$":4~'#29403$#29403'" DO .5 <- ':1~:1'~#1 DO .5 <- "V!5~#2'$#1"~#1 DO .2 <- :2~'#29403$#29403' DO (1530) NEXT DO .6 <- ':1~:1'~#1 DO .6 <- "V!6~#2'$#1"~#1 PLEASE DO .5 <- 'V.6$.5'~#1 DO .1 <- :3~#29524 DO .2 <- #0 DO (1520) NEXT PLEASE DO :2 <- :1 PLEASE DO .1 <- :4~#29524 DO (1520) NEXT DO (1509) NEXT PLEASE DO .5 <- "V.5$':4~#1'"~#1 DO :1 <- :3 DO :2 <- :5 DO (1509) NEXT PLEASE DO .5 <- "V.5$':4~#1'"~#1 PLEASE RETRIEVE :4 (1541) DO :4 <- .5 DO (1543) NEXT (1542) DO (1544) NEXT PLEASE DO (1999) NEXT (1543) DO (1001) NEXT (1544) DO REINSTATE (1541) PLEASE REINSTATE (1542) PLEASE RETRIEVE :1 + :2 + :5 + .1 + .2 + .5 + .6 DO RESUME #2 (1900) DO STASH .2 + .3 + .5 DO .1 <- #0 DO .2 <- #1 PLEASE DO (1901) NEXT (1901) DO FORGET #1 DO %33 .1 <- 'V.1$.2'~'#0$#29524' DO %33 .1 <- "V!1$".2~#59048"'"~"#0$#29524" DO .2 <- !2$#0'~'#9841$#1' PLEASE DO .5 <- 'V"!2~.2'~#2"$#1'~#1 DO (1902) NEXT DO (1901) NEXT (1902) DO (1001) NEXT DO RETRIEVE .2 + .3 + .5 PLEASE RESUME #2 (1550) DO STASH :1 + :4 + :5 + .5 DO :3 <- #0 DO .5 <- 'V"':2~:2'~#2"$#1'~#1 DO READ OUT #3000 + .5 PLEASE DO (1551) NEXT DO :4 <- #1 PLEASE DO (1553) NEXT (1553) DO FORGET #1 DO .5 <- :2~'#19683$#0' DO .5 <- "?!5~#2'$#1"~#1 DO READ OUT #4000 + .5 DO (1552) NEXT DO :2 <- ":2~'#0$#29524'"$"'":2~'#9841$#0'"$# 0'~'#9841$#1'" PLEASE DO :4 <- ":4~'#0$#29524'"$"'":4~'#9841 $#0'"$#0'~'#9841$#1'" DO (1553) NEXT (1552) DO (1001) NEXT (1556) PLEASE FORGET #1 DO :5 <- "'?":1~'#29524$#0'"$":2~'#29524$#0'"' ~'#0$#29524'"$"'?":1~'#0$#29524'"$":2~'#0$ #29524'"'~'#0$#29524'" DO .5 <- '&"':2~:5'~'"'^"'?:5~:5' ~'#29524$#0'"$#19683'~'#0$#29524'" $"'?:5~:5'~'#0$#29524'"' "$"':5~:5'~#1"'~#1 DO .5 <- "?!5~#2'$#1"~#1 DO NOTE THAT THE ABOVE THREE LINES DO NOT WORK DO READ OUT #1000 + .5 DO (1554) NEXT DO :5 <- :3 DO (1510) NEXT PLEASE DO :1 <- :3 DO READ OUT #5000 DO :3 <- "'^":4~'#29524$#0'"$":5~'#29524$#0'"' ~'#0$#29524'"$"'^":4~'#0$#29524'"$":5~'#0$ #29524'"'~'#0$#29524'" DO (1556) NEXT (1554) PLEASE DO (1001) NEXT (1555) DO FORGET #1 DO .5 <- '?":4~#2"$#1'~#1 DO READ OUT #2000 + .5 DO (1551) NEXT DO :2 <- ":2~'#0$#29523'"$":2~'#29524$#0'" DO :4 <- ":4~'#0$#29523'"$":4~'#29524$#0'" PLEASE DO (1556) NEXT (1551) DO (1001) NEXT PLEASE RETRIEVE :1 + :4 + :5 + .5 PLEASE RESUME #2
I have yet to write routine (1550), 10-trit (roughly 32-bit) division. Once I have implement this I can go on to write (1050) and (1910). The problem I am encountering is that of 10-trit comparison.
The (1550) routine works by repeatedly shifting the denominator leftwards by one trit (thus multiplying by 3), and subtracting the denominator from the numerator. (In the case of the denominator being zero, we set the overflow bit (.4), and return. Let us call the denominator y, and the numerator x, so that we are calculating x/y. Let the quotient be q, and the remainder r. We repeatedly subtract y from x, until x < y.
If it takes us two subtractions to do this, we set the current trit of the quotient to 2. If it takes us only one subtraction, we set the current trit to 1, otherwise we set it to 0. Let us also have a number b, representing the current trit that we are twiddling. This starts at 2, and we use the V (or) mechanism to OR it with the current quotient, thus setting that bit, then we shift b leftwards by one trit. We repeat until b is 0, i.e. we have shifted the 2 trit off the edge.
This is clearly a constant time operation. The above algorithm is not, however, perfected. I haven't determined a way to set the current bit of the quotient to 2 or 1 or 0 depending on the amount of times we had to subtract y from x. I suspect we may have to either:
- Have two variables which contain the bit to OR into the quotient.
I hope you understood all that, and I also hope someone knows how to test for 10-trit greater-than in TriINTERCAL. [grin]
At the moment, I think it should look something like this:
DO :5 <- "'?":1~'#29524$#0'"$":2~'#29524$#0'"' ~'#0$#29524'"$"'?":1~'#0$#29524'"$":2~'#0$ #29524'"'~'#0$#29524'" DO .5 <- '&"':2~:5'~'"'?"'?:5~:5' ~'#29524$#0'"$#19683'~'#0$#29524'" $"'?:5~:5'~'#0$#29524'"' "$"':5~:5'~#1"'~#1 DO .5 <- "?!5~#2'$#1"~#1