OKlibrary  0.2.1.6
MaximaTechniques.hpp File Reference

Documentation on how to write programs in Maxima/Lisp. More...

Go to the source code of this file.


Detailed Description

Documentation on how to write programs in Maxima/Lisp.

Programming at the Maxima/Lisp level in the OKlibrary

Naming conventions

File names

  • All Maxima-code is placed in "Filename.mac"-files.
  • Exceptions are only demo-files (placed in demos-subdirectories), which have the suffix ".dem".
  • Lisp-files have suffix ".lisp".

Testing and checking

Input checking

  • No input validation is performed (at the Maxima/Lisp level), since
    1. it makes the code hard to write, read, and maintain,
    2. creates considerable runtime overhead,
    3. and is inadequate at this level, where experimentation and interaction is the focus,
    4. and finally, Maxima represents the set-theoretical level, the (full) mathematical world.
  • For a definition "D" of a special type of Maxima-objects, for examples graphs or clause-sets, predicates "D_p" (for example "g_p" or "cs_p") are provided, which can be used in the (higher-order) unit-tests.

Maxima-specific problems

Memory limits

See ComputerAlgebra/MaximaInternals/MemoryManagement.mac for the (Ecl-specific) functions handling memory limits.

Recursion

  • Consider
    fib_mem[n] := if n <= 1 then n else fib_mem[n-1] + fib_mem[n-2]$
    fib_mem[6100];
    Maxima encountered a Lisp error:
     C-STACK overflow at size 8421376. Stack can probably be resized.
       
  • In Ecl we can resize the c-stack:
    get_c_stack_ecl();
      8421376
    set_c_stack_ecl(2^24);
      16777216
    
    is(fib_mem[6100] = fib(6100));
      true
       
  • Another (general) possibility is to write for memoised recursive functions a wrapper which calls the function bottom-up.
  • _fib_mem[n] := if n <= 1 then n else _fib_mem[n-1] + _fib_mem[n-2]$
    fib_mem(n) := (for i : 0 thru n-1 do _fib_mem[i], _fib_mem[n])$
    is(fib_mem(6100) = fib(6100));
      true
       

Definition in file MaximaTechniques.hpp.