Programming Examples



Applications

loan.4thMortgage Loan Payment Calculator
lf.4thA Simple Word Processor by Leo Wong
minispread.4thA Simple Spreadsheet by ChessPlayer
headlines.4thSearch web pages for item of interest
notes.4thSimple notes database
speech.4thInterface to the Festival Text To Speech System
ipsubnet.4thIP Subnet Calculation


Games and AI

magic.4thMagic Squares
hanoi.4thTowers of Hanoi puzzle
tetris.4thTetris by Dirk Uwe Zoller
corewars.4thBattling Programs
pentomino.4thSolutions to the Pentomino Puzzle by Bruce Hoyt
sudoku.4thSudoku Puzzle Solver by Robert Spykerman
life.4thConway's Game of Life by Leo Wong
animal.4thAnimal Guessing Game by Ed Beroset
eliza.4thEliza psychoanalysis game
gps.4thGeneral Problem Solver (AI example)
shrdlu.4thSon of SHRDLU AI game by Marcel Hendrix
strek.4thSuper Star Trek by Mike Mayfield and others
tscp.4thTSCP Tom's Simple Chess Program by Ian Osgood
tscp-tgfx.4thTSCP Chess Program with Text Graphics (screenshot)
chessboard.4thText Graphics Chessboard
backprop.4thBackpropagation Neural Network Module by Marcel Hendrix
ocr.4thOptical Character Recognition Example of Neural Net by Marcel Hendrix
react.4thVisual Reaction Time Measurement
keycal.4thKey Event Processing Time Measurement
stem.4thPorter's Suffix Stripping Algorithm by Wil Baden ( info)


Programming Tools and Libraries

utils.4thUseful Words for kForth
asm-x86.4thAn assembler for x86 Processors
asm-x86-examples.4thAssembly Code Examples for asm-x86
syscalls386.4thLinux System Calls from Forth
fpu-x86.4thSet Precision, Rounding Mode, and Exception Controls on x86 FPUs
signal.4thSignals Interface
signals-ex.4thExample of Signal Handling
spinlock-ex.4thExample of Mutual Exclusion via Spinlock (x86)
ans-words.4thAdditional ANS Forth Words for kForth
ansi.4thANSI Terminal Control
strings.4thString Manipulation/Number Conversion
lists.4thLisp like List Processing
lists-test.4thTest List Words
dump.4thMemory Display
files.4thFile Access (x86 Linux version)
files.4thFile Access (Windows version)
files.4thFile Access (PowerPC OS X version)
ftest.4thFile i/o Example
struct.4thC-like structures for Forth by Anton Ertl ( description)
struct-ext.4thByte-aligned fields for struct.4th
mini-oof.4thBernd Paysan's Object-Oriented Extensions to Forth (adapted for kForth)
mini-oof-demo.4thDemonstrate Object-Oriented Programming Using mini-oof
textbox.4thColor Boxes Using Text Graphics
macro.4thMacros in Forth
catch-throw-ex.4thExample of Using CATCH and THROW in Forth
ttester.4thGeneral Test Harness by J. Hayes and A. Ertl
core.4thTest Suite for ANS Forth Core Words by John Hayes
tester.4thUtility Words Needed by core.4th
kforth2pfe.4thInterface to run kForth Programs Under the Portable Forth Environment (PFE)
getline.4thEnhanced version of READ-LINE by Bill McCarthy
fsm.4thFinite State Machine Example
user.4thDetermine User Properties (Linux)


Data Encoding and Conversion

crc-16.4th16-bit CRC (Cyclic Redundancy Check) Calculation by Gordon Charlton
crc-32.4th32-bit CRC Calculation by Wil Baden
crc-32-x86.4th32-bit CRC Calculation in Assembly Language by Petrus Prawirodidjojo
forth2html.4thCreate HTML pages from Forth Source Files
dos2unix.4thDOS Text to Unix Text File Conversion
scr2txt.4thBlock File to Text File Conversion
lz77.4thLZ77 Data Compression Algorithm by Wil Baden
arcfour.4thARCFOUR Data Encryption/Decryption Algorithm by Neil Bawd
base64.4thBase64 Content Transfer Encoding/Decoding by Wil Baden
hmac-md5.4thMD5 Calculation by Jabari Zakiya


Interfacing and Data Acquisition

mouse.4thMouse Interface for Linux Consoles
serial.4thSerial Port Interface (x86 Linux)
serial.4thSerial Port Interface (Windows)
terminal.4thSimple Terminal Example of Using serial.4th (x86 Linux)
terminal.4thSimple Terminal Example of Using serial.4th (Windows)
serbuf.4thMeasure Linux Serial Driver Buffer Size
hexterm.4thDisplay Incoming Serial Port Data (Linux)
adio.4thData Acquisition with the B&B ADIO12 Parallel Port Interface (Linux)
ioctl.4thGenerate IOCTL numbers under Linux
gpib.4thInterface to the open source Linux GPIB driver (for Linux 2.6.x kernel)
nigpib.4thInterface to National Instruments Linux GPIB driver (for Linux 2.4.x kernel)
hp34401.4thInterface to the HP34401A Multimeter (Linux)
hpcommon.4thCommon Definitions for HP/Agilent Digital Scopes (Linux)
hpwfmhdr.4thHeader Structure for Digital Scope waveforms (Linux)
hp54750.4thInterface to the HP54750 Digitizing Scope (Linux)
hp546x.4thInterface for Agilent 546x series of Digital Scopes (Linux)
hp.4thText Mode Menu Interface for Agilent 546x Digital Scopes (Linux)


Mathematics

primes.4thPrime Numbers
benchpin.4thCalculate number of primes less than or equal to n
horst.4thFactorize numbers by Albert van der Horst
pispigot.4thDisplay PI to arbitrary number of digits by Albert van der Horst
interp.4thLinear Interpolation with Integer Tables by Chris Jakeman (picture)
cubic.4thThird Order Polynomial Interpolation with Integer Tables by Brad Eckert


Scientific Library

This library provides modules for some commonly used algorithms in scientific computing. Many of the modules have been ported to kForth from the Forth Scientific Library (FSL). The original FSL modules were written for Forth systems which use a separate floating point stack. The kForth versions of these modules, in addition to being modified for a unified data/fp stack, have also been revised and improved in some aspects, most notably with regard to the test code. Versions of the revised FSL modules for Forth systems which use a separate floating point stack may be found in ftp://ccreweb.org/software/gforth/fsl/.

FSL Auxiliary Files

fsl-util.4thFSL Definitions of Arrays, Matrices, and other Utilities
fsl-test-utils.4th Utility Words for Automated Testing of the FSL Modules
fsl-tester.4th Automated Tests of Selected FSL Modules
dynmem.4thFSL Routines for Dynamic Memory Use

Complex Numbers

complex.4thComplex Arithmetic and Function Words by J.V. Noble and D. N. Williams
complex-test.4thTest Words in complex.4th by David N. Williams

Finding Roots

quadratic.4thSolve Quadratic Equation with Real Coefficients
cubic.4thFSL Cubic Equation Root Solver
regfalsi.4thFSL Function Root Finder

Special Functions

expint.4thFSL Real Exponential Integral
elip.4thFSL Complete Elliptic Integral
logistic.4thFSL Logistic Function and its First Derivative
horner.4thFSL Polynomial Evaluation by Horner's Method
polys.4thFSL Evaluate Special Polynomials: Chebyschev, Hermite, Laguerre, generalized Laguerre, Legendre, and Reverse Bessel
sph_bes.4thFSL Regular Spherical Bessel Functions (j_0 through j_9)
factorl.4thFSL Factorial Function
gamma.4thFSL Gamma, LogGamma, and Reciprocal Gamma Functions
pcylfun.4thFSL Parabolic Cylinder Functions and Related Confluent Hypergeometric Functions

Power Series

shanks.4thFSL Nonlinear Transformation of Series

Differentiation

derivative.4thNumerical Derivative of x,y Data

Integration

adaptint.4thFSL Adaptive Integration Using Trapezoid Rule
gauleg.4thFSL Gauss-Legendre Integration of Functions

Solution of Ordinary Differential Equations

runge4.4thFSL Runge-Kutta Routines for Integrating Ordinary Differential Equations
lorenz.4thDemonstrate Use of FSL runge4.4th with Lorenz Differential Equations (picture)

Solution of Linear Systems

gaussj.4thFSL Linear System of Equations Solver Using Gauss-Jordan Elimination ( loader for testing gaussj)
lufact.4thFSL LU Factorization of a Square Real Matrix
dets.4thFSL Determinant of an LU Factored Matrix
backsub.4thFSL Linear System of Equations Solver Using LU Factorization
invm.4thFSL Inverse of an LU Factored Matrix
hilbert.4thFSL Finite Segments of Hilbert Matrices, their Inverses, and Determinants
determ.4thDeterminant of a Square Matrix

Curve Fitting

polyfit.4thLeast-Squares Polynomial Fitting (example of line fitting; example of polynomial fitting)
curvefit.4thNon-linear Curve Fitting
gfit-curvefit.4thDemonstrate Use of curvefit.4th ( picture), (see also gfit-levmarq.4th)
func_Ngauss.4thCalculate sum of N Gaussian peaks and baseline
wfms01-1.datSample Data File for Curve Fitting Example
levmarq.4thFSL Levenberg-Marquardt Nonlinear Curve Fitting
gfit-levmarq.4thDemonstrate Use of FSL levmarq.4th

Fast Fourier Transform

four1.4thFast Fourier Transform (one dimension)
four1-test.4thFFT Example of Square Pulse
fft-x86.4thAssembly Code FFT (callable from Forth)

Probability and Statistics

permcomb.4thFSL Permutations and Combinations
gauss.4thFSL Gaussian Probability Function
stats.4thStatistics
histogram.4thBinning Data

Random Number Generators

isaac.4thFSL ISAAC Random Number Generator
prng.4thFSL GGUBS Floating Point Random Number Generator
r250.4thFSL Fast Pseudo-Random Number Generator
noise.4thUniform and Gaussian Random Number Generation
random.4thAssorted Simple Random Number Generators
ran-next.4thDonald Knuth's Recommended Random Number Generator
mersenne.4thMersenne Twister (2002) Random Number Generator

Clebsch-Gordan Coefficients

cg.4thWigner 3-j Symbols and Clebsch-Gordan Coefficients
cg-test.4thTests for cg.4th

Astronomical Calculations

jd.4thJulian Day and Calendar Calculator
sun.4thSunrise and Sunset Calculator by Neal Bridges

Miscellaneous Utilities

shellsrt.4thFSL Shell-Metzger Sorting for FP Array
crc.4thFSL 16-bit CRC (Cyclic Redundancy Check) Calculation by Gordon Charlton
machar.4thDetermine floating point machine charactersitics by David N. Williams

Deprecated

matrix.4thMatrix Words (deprecated in favor of FSL arrays and matrices)
matfiles.4thWrite and Read Matrix Files
zmatrix.4thComplex Floating Point Matrices
zeigen22h.4thCompute Eigenvalues and Eigenvectors of a 2x2 Hermitian Matrix


Science Demos

grating.4thCompute Diffraction Grating Properties
pde1.4thNumerical Solution of Electrostatics Boundary Value Problems (sample solution)
sl.4thSemiconductor Laser Rate Equation Solver ( instructions)
lk.4thLang-Kobayashi Equation Solver (picture)
lkspec.4thTime-Averaged Optical Spectrum of Lang-Kobayashi System
naacb.4thNeutral Atom-Atom Collision Broadening of an Atomic Spectral Line
qm4.4thQuantum Mechanics Demonstrations: Properties of Eigenfunctions and Operators
qm6.4thQuantum Mechanics Demonstrations: Pauli Spin Matrices, Spinors, and Measurement Probabilities
qm8.4thQuantum Mechanics Demonstrations: Bloch Equations, Rabi Oscillations, and Inversion of a Two-Level System
henon.4thExplore Chaos in the Henon Map (picture)
ogy.4thChaos Control Example Using the Ott-Grebogi-Yorke Method
tpf.4thControl of Unstable Periodic Orbits in a Chaotic Electronic Circuit (period-1, period-2, high-res upos, uncontrolled)


Source examples for kForth embedded inside of the application xyplot are provided here.