complex arithmetics

Featuring the Dragonfly web framework

complex arithmetics

Postby thefausap » Thu Sep 11, 2014 10:09 pm

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
Attachments
tcomplex.zip
test file for both of them
(377 Bytes) Downloaded 106 times
perm.zip
permutations library
(1.14 KiB) Downloaded 105 times
complex_lib.zip
complex number library
(966 Bytes) Downloaded 113 times
thefausap
 
Posts: 2
Joined: Tue Sep 09, 2014 11:33 pm

Re: complex arithmetics

Postby kosh » Thu Sep 18, 2014 1:23 pm

There is a point to problem.

Code: Select all
> (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:
Code: Select all
(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
Code: Select all
#!/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)
kosh
 
Posts: 68
Joined: Sun Sep 13, 2009 5:38 am
Location: Japan

Re: complex arithmetics

Postby Lutz » Thu Sep 18, 2014 8:26 pm

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.
Lutz
 
Posts: 5258
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California


Return to So, what can you actually DO with newLISP?

Who is online

Users browsing this forum: No registered users and 2 guests