mathemaTcl

Arjen Markus (10 february 2017) MathemaTcl is the name I chose for a collection of mathematical libraries (mostly from Netlib) that can be accessed from Tcl.

You can find the code here: [1 ].

To build it (or parts of it) you need a C and possibly a Fortran compiler that can build extensions for your version of Tcl.

Currently the following extensions are available:

  • CDFLIB - evaluate cumulative probability density functions and their inverses
  • CEPHES - a library for evaluating special mathematical function, such as the various Bessel functions and exponential integral functions.
  • FFTPACK - a one-dimensional FFT package (derived from the SLATEC library)
  • GLOBAL - a package to find the global minimum of a function of one or several variables
  • MILLER - a package containing several utilities by Alan Miller (currently: roots of a polynomial and a root of a function within a given interval)
  • ORDERPACK - a library for a variety of ordering and ranking algorithms
  • QUADPACK - a package for the automatic integration of functions over finite or infinite intervals
  • RANDOM - a library to generate random numbers adhering to well-known distributions, such as normal, Student's t, chi-square etc.
  • SPECFUNC - a collection of routines to evaluate special mathematical functions, such as Bessel functions of the first and second kind, exponential integrals and the like.
  • STROUD - a collection of quadrature rules for regions like cubes, spheres, pyramids, various weighting functions
  • WAVELIB - a library for wavelet transforms

Warning: This is work in progress at the moment. For most packages documentation is now available and several simple demonstrations, but they should be tested more extensively.

The build procedure has now been tested on a variety of systems (plain Windows, Cygwin and MinGw64/MSYS2 as well as Linux). Hm, the pkgIndex.tcl file may not be suitable yet for Linux, something I need to check.

Important note: I recently found out that for 64-bits platforms there is a portability problem - as I use "long" and "int" as equivalent data types, the code will likely not work properly if the C compiler distinguishes the two. This is NOT the case for MSVC++/Intel Fortran on Windows, but it is true for GCC (gcc/gfortran). I will have to revise the code to take care of this.

(updated: 19 september 2017)


Demo

# demo_fftpack.tcl --
#     Demonstration of the FFTPACK wrapper
#
#     Note: the transform is not normalised, hence the factor "size"
#
package require tcl_fftpack

set size 101

set transform [::fftpack::createTransform1D $size]

set PI [expr {acos(-1.0)}]

for {set i 0} {$i < $size} {incr i} {
    lappend values [expr {0.4+cos(2.0*$PI*$i/100.0)+sin(4.0*$PI*$i/100.0)}]
}

set oldvalues $values

set transformed [$transform forward $values]

puts "Transform:"
for {set i 0} {$i < $size/2+1} {incr i} {
    puts [format "%12.4f %12.4f" [lindex $transformed $i 0] [lindex $transformed $i 1]]
}

set reconstructed [$transform backward $transformed]

puts "Reconstructed and old values (unnormalised):"
for {set i 0} {$i < $size} {incr i} {
    puts [format "%12.4f %12.4f" [lindex $reconstructed $i] [expr {$size*[lindex $oldvalues $i]}]]
}