complex arithmetics

Started by thefausap, September 11, 2014, 03:09:59 PM

Previous topic - Next topic

thefausap

Hello all,



attached there's a "library" for newlisp to perform mathematical operations with complex numbers.

Such numbers are created with a list with the format : '(re im).

I added and tested all the included functions.



I also created a library for complex matrices determinant. The matrices needs to be written in column-major order.

I borrowed the permutation code from the newlisp web site and I added the function to calculate the parity of permutation.



Please feel free to test it and comment it.

This is my first newlisp program, and I'm sure there're a lot to improve.



Regards

kosh

#1
There is a point to problem.


> (constant '*2pi* (mul 3.14159265358979323846264338327950288419716939937510 2))
3.159714599e+020
> (read-expr "(mul 3.14159265358979323846264338327950288419716939937510 2)")
(mul 3.141592653589793115997963468544185161590576171875 50288419716939937510L 2)


newlisp parser reads too long a numeric value (or symbol) without no warning.

Therefore, it is better to avoid such writing.



I recommend PI defined as:
(constant 'pi (mul 4 (atan 1)))  ; or short written 3.141592654

P.S. I tried writing a mandelbrot set. like this http://www.newlisp.org/complex.cgi">//http://www.newlisp.org/complex.cgi
#!/usr/bin/env newlisp

(load "complex_lib.lsp")
 
(for (y -1 1.1 0.08)
  (for (x -2 1 0.04)
    (letn ((c 126)
           (z (cmplx x y))
           (a z))
      (while (and (begin
                    (setq z (cadd (cmul z z) a))
                    (< (abs (cmod z)) 2))
                  (< 32 (dec c))))
      (print (char c))))
  (println))
 
(exit)

Lutz

#2
Currently decimal-point numbers are limited to 32 characters including the decimal point and sign. Which is about double the digits precision which internally can be distinguished in IEEE-754 floating point numbers.



This character limit will be increased in the next version.