2012/9/17 pingon begand <sbronfion@xxxxxxxxx>: > Is there a module/binding for your complex number library? I am interested > in that part and I cannot find anything. Hi, to answer your question, the complex stuff in GSL Shell is coming from the GSL library and from the native support in LuaJIT for complex numbers as defined in the C99 standard. The type gsl_complex is defined in the GSL library: http://www.gnu.org/software/gsl/manual/html_node/Complex-Numbers.html and many functions on complex numbers ar available as well. The only trick here is that you can identify the gsl_complex type with C99 "double _Complex" aka "complex". So in the file "gsl.lua" you will find the following cdef: typedef complex gsl_complex. With this trick all the complex numbers' functions from the GSL library are immediately avaliable using the FFI interface. The definitions are in the "matrix.lua" file near the function "c_function_lookup". I admit that it is a little bit unfortunate place to define complex numbers :/ The other trick is to define arithmetic metamethods for complex types using the function ffi.metatype. This is also done in "matrix.lua". Actually the reason why matrix and complex are implemented in the same file is that they need to have common arithmetic metamethods because in GSL shell you can add or multiply a complex numbers with a real or complex matrix. So, if you want to isolate the complex number stuff you have to take the file "gsl.lua" and "matrix.lua" and keep only the stuff related to complex numbers. > Here are more open questions : > Do you think that 'GSL-Shell' will offer the same function interface as in > julia? Unfortunately the answer to this question is negative. Julia is designed from the beginning to support mathematical operations while Lua is a generic purpose programming language. For example in LuaJIT you cannot refer to an element of a matrix like m[i, j] as it would be natural for matrices. You don't have a specific syntax for matrix literals and, more important matrix operations are inherently inefficient because evaluation is not delayed. So if you write: a + 2*b + 2*c where a, b and c are matrices Lua will: - create a new matrix equal to 2*b - create a new matrix equal to 2*c - create a new matrix to sum a + 2*b - create a new matrix to sum (a + 2*b) with 2*c Of course this is a disaster in term of efficiency. The evaluation should be delayed to use BLAS operations to evaluate efficiently the expression. This problem exist also for the multiplication by a transpose. The BLAS function allows to evaluate it without the need of actually creating the transpose matrix but with Lua you cannot. Unfortunately the "goto" statement recently implemented in LuaJIT does not help with this problem :-) AFAIK the only solution is to create a new language that compile to Lua but for the moment I didn't take this direction. > Will luajit be a dependence instead of a 'fork'? Not now. In future who knows... :-) Francesco