Novice Forth & Slide-rule.4th

FIG stuff


Novice Forth

10/15/2010

I have written some ANS-Forth code that I have put in the public-domain (BSD license) as a contribution to the Forth community. Most people who get interested in Forth will write a Forth compiler as an exercise in assembly-language, but they never write any applications in Forth. By comparison, my novice package is oriented toward writing applications. I also provide some small to medium-sized example applications to prove to the novice that writing non-trivial programs in Forth is possible. The novice may wish to upgrade these demos as an exercise, or at least study them to see how applications are written.

The novice package includes the following (and more):

NOVICE.4TH --- This file is required by most of the other files. Here we have simple data structures such as records and arrays. I have fixed a lot of problems in ANS-Forth, such as there being no way to determine if a memory block came from ALLOCATE or ALLOT, or what the size of the memory block is. I have dispensed with CREATE DOES> altogether, and use :NAME instead. This is another example of fixing a problem in ANS-Forth --- making :NAME available is the primary purpose of my releasing this software.

LIST.4TH --- This file contains a linked-list data-structure. Lists can be used in much the same was as sequences are used in Factor. This file also contains lists of strings (SEQ lists) and comma-delimited strings (DECOMMA lists) that are useful in many applications. All in all, the list code is the most practical of all the code that I have written. My slide-rule program is a good example of using lists as the basic data-structure for the entire program.

ASSOCIATION.4TH --- This file contains code for associative arrays. It uses Left-Leaning Red-Black (LLRB) trees internally. In addition to FIND-KEY, INSERT and DELETE, I also have code for extracting nodes inside or outside of a range. I prefer lists, but a lot of people (Awk and Lua programmers, for example), use associative arrays as their primary data-structure. This is not a bad way to program, and my code will help you do so in Forth.

CF.4TH --- This file contains Nathaniel Grosman's continued-fraction program (Long Divisors and Short Fractions (Forth Dimensions Sept/Oct 1984)). The purpose of this program is to calculate rational approximations for use by */ or M*/ to multiply that rational by an input parameter. This is the only major example of code included in the novice package that I didn't write myself.

RATIO.4TH --- This file contains code based on LIST.4TH supporting lists of rational numbers. These can provide better accuracy than floating-point numbers for repeating decimals.

QUEENS.4TH --- This file contains code to solve the famous N-Queens problem. I use a non-recursive backtracking algorithm of my own design. This is the only non-trivial program I have in the package that is *not* recursive, which is somewhat ironic as the N-Queens problem is typically given to novices as a classic example of recursion.

SYMTAB.4TH --- This file contains a symbol table. The algorithm is my own invention. If you have a lot of memory (modern desktop computers do), then a hash table is a better choice. Given limited memory, such as for an MS-DOS computer (one 64K segment for the headers), then symtab is the best choice. Symtab assumes that there is a lot of variance in how often the nodes are accessed, which is typical for a symbol table. If all the nodes are roughly equal in popularity, which is typical for an associative array, then ASSOCIATION.4TH would be a better choice.

LowDraw.4th
LowDrawStrategies.4th --- These files do an analysis of low-draw poker using a recursive-descent search. This is not a Monte-Carlo "analysis," but it is a *complete* analysis of the probabilities. This software also allows the user to set up customized situations and obtain the probabilities for the various options (fold or call). This is useful for when you wake up the next morning with a loser's hangover, and you want to prove to yourself that you chose the *correct* option --- even though you lost the hand and all of your money.

All of the source-code files have associated text files (same name with a .TXT extension) that provide documentation. I also have a file NOVICE.PDF that discusses the novice code. This is a short file that only discusses a few of the more important aspects of the code. It is written for advanced programmers who are deciding if they want to recommend my novice package to novices or not. I can be contacted at hughaguilar96 -at- yahoo.com for comment. If you have any software that you would like included in the novice package, I would be willing to do this if I think that it is a good example of using the novice package and/or would be useful for novices to learn from. I would give you credit for writing the code.

Hugh Aguilar
hughaguilar96 -at- yahoo.com

novice.forth.zip - 239 Kb zip file

Slide-rule.4th

10/15/2010

The slide-rule package contains everything in the novice package, and also contains the SLIDE-RULE.4TH program as well as the many associated files that go along with it. The slide-rule program is packaged separately because it is quite large --- it is definitely pushing the upper limits of "medium-sized."

I provide code for several slide-rules of my own design. The program can also be easily modified to make custom slide-rules. I have some 52 scales written already. These include a lot of scales that are useful for electrical engineers, and also some which are useful for financial calculations. The user can mix-and-match scales to create a custom slide-rule. This can be done without any knowledge of Forth programming, using ye olde cut-and-paste programming (see FINANCIAL.4TH as an example of an extension to the base program). Also, with a modicum of Forth knowledge, the user can upgrade the software to include custom scales, or at least customizations to already-written scales (such as including gauge marks to support specific calculations). As an example of this, I have provided a custom scale that is useful for calculating Texas Hold'Em pot odds. Slide-rules are fast enough to be feasible at the poker table, which is not true of pocket calculators (calculations involving ratios are generally faster with a slide-rule than a calculator).

The program supports two-sided slide-rules, and also one-sided slide-rules (which have scales under the slide and also on the back of the slide). These slide-rules can be made to any length. I have several sets of "reduction values" which determine how many marks are generated within each section of each scale. The larger sized slide-rules can support more marks, which means that there is less interpolation required of the user and better accuracy. Generally speaking, slide-rules 6" long use the POCKET-SIZE reduction values, slide-rules less than 16" long use the FULL-SIZE reduction values, and slide-rules of 16" or more use the LARGE-SIZE reduction values. My software doesn't at this time support wall-size slide-rules (4 foot or longer), although I could upgrade it to do so if anybody is interested. In addition to straight slide-rules, the program also supports round slide-rules, such as could be made into key-fobs.

The program generates gcode for a CNC milling machine for use in etching the marks and labels on a black-anodized aluminum slide-rule. The anodization gets scratched off to reveal the shiny aluminum underneath. The idea is to use a diamond-tipped scribe rather than a rotating tool, in order to make the marks as thin as possible. This would be a good option for onesy-twosy manufacture. The software could be upgraded to generate gcode for a laser-etcher, which might work for larger quantities. I would have to have access to the laser to make this upgrade though. What I have right now should work on any milling machine though. The small milling machines that are used for making printed-circuit boards might be the best choice.

The program also generates PostScript for use in photo-lithography of an aluminum slide-rule. The guru Don Lancaster suggested some possible products that could be used. This is most likely the best option for manufacturing slide-rules in large quantities at an affordable price. Some print shops have printing devices that are capable of 2500 dots per inch, which should provide adequate precision for a slide-rule. Also, toy slide-rules can be made by printing to adhesive labels using a common laser-printer. A salesperson at Avery Office Products suggested using Permanent Durable ID labels #6575. I don't support PostScript for key-fob slide-rules at this time, but only for straight slide-rules.

In addition to generating gcode and PostScript, the program can also dump raw data into disk files. This feature was requested by a C++ programmer who wanted to write a front-end for my software using wxWidgets. I myself may eventually write a GUI front-end for the program; the program just has a simple text-based user-interface right now. The program could be upgraded to generate SVG or any other format of data. The gcode generation was written first, and the PostScript generation was a later upgrade. The code that generates PostScript provides a good example of how the base program can be upgraded for new data formats. The program is pretty robust, in the sense that it was designed to be easily upgraded.

I have two documents available. SLIDE-RULE-BRIEF.PDF is a short document that provides a quick introduction to how the program works. SLIDE-RULE.PDF is a much longer book (about 300 pages) that provides more extensive information about the slide-rule software, and also extensive information about some non-computer encryption systems that I have invented. I also provides documentation on the LowDraw poker software as well as a discussion on gambling with cards. In addition to the technical material, I also have a discussion about *why* slide-rules should be manufactured. Briefly, the purpose of the slide-rules is to put them in time-capsules (usually in graves) so that if our civilization collapses, the people in the future (3 or 4 centuries from now) can find the slide-rules and get a jump-start on rebuilding civilization. I have read about civilizations collapsing in the past (the Roman Empire being the most famous, but we have the Toltecs and the Mayans here in America as other examples). My intention with the time-capsules is to reduce the length of the Dark Ages that will follow the collapse of the American civilization by giving the people of the future a legacy from our own civilization that has practical use for them. The advantage of slide-rules is that a person can figure them out through experimentation, even if the person does not read English. I am familiar with how much English has changed in the last 500 years (I read about the Middle Ages quite a lot), and I expect that the language will change as much again in the next 500 years, which is why I think that time-capsules containing books would not be useful.

I can be contacted at hughaguilar96 -at- yahoo.com for comment on any of my software. The International Slide-Rule Group (ISRG) mailing-list is the best place for contacting me about the slide-rule program. People on ISRG have made suggestions for improvements to the program which I have in some cases followed up on. The slide-rule program was originally written in a coding blitz which took place in January of 2010. Since that time however, I have made a lot of upgrades to the slide-rule program and the underlying novice package.

Hugh Aguilar
hughaguilar96 -at- yahoo.com

slide-rule.forth.zip - 3.8 Mb zip file


<--  FIG Home page