sasagawa888 / eisl

ISLisp interpreter/compiler
Other
275 stars 23 forks source link

matrix.lsp gives compiler error undefined <general-vector> #307

Closed sanjayjain159 closed 6 months ago

sanjayjain159 commented 6 months ago

Dear Sir,

I ran eisl -c, then (compile-file "matrix.lsp") and obtanied compile time error noted above. Where am I going wrong?

sasagawa888 commented 6 months ago

I was able to reproduce the bug here as well. It's a bug in the compiler. Please wait for a while as we will fix it.

sasagawa888 commented 6 months ago

The modification has been made and compilation is now possible. The compiler has been adapted to support built-in classes and user-defined classes. However, the compiled Matrix library is not functioning correctly. It is unstable due to dependencies on other libraries. There are plans to completely rewrite the matrix library at some point.

sanjayjain159 commented 6 months ago

Dear Sir,

My interest in compiling matrix.lsp was because I have to invert a 200x200 floating point matrix and interpreter is taking time. So I feel compiling basic matrix functions should be useful.

Related to the same is slow result on fib(40) using naieve recursion to calculate fibonacci number, perhaps because of mixing in of bignum. If one does not want to compile the function, when it becomes as fast, and also as 'frozen' as C, is there a way to avoid it seeking bignum?

sanjayjain159 commented 6 months ago

I need to invert 200x200 matrix for data analysis of electrical measurements.

sanjayjain159 commented 6 months ago

Upon reconsideration, I do not see any need to compile matrix.lsp for my purposes,

sasagawa888 commented 6 months ago

At this point, I will organize and optimize the matrix library. Thank you.

sasagawa888 commented 6 months ago

I have rewritten the matrix library to be independent of other libraries. Also, I made it a simple code so that the compiler generates efficient code. Please try it out.

sanjayjain159 commented 6 months ago

Dear Sir, I tried mult, matrix-det, and matrix-inverse. There is some difficulty with matrix-det, I think. Here is what I did:

eisl -l library/matrix.o (defglobal x1 (create-array '(3 3) 0.0)) (setq x1 #2a((1.1 2.1 3.1) (4.2 5.2 6.2) (7.3 8.3 9.3))) (matrixp x1) (matrix-det x1) here I got the value 0 for the det. It seems that is an error.

On 23 March 2024 9:07:57 AM IST, kenichi sasagawa @.***> wrote:

I have rewritten the matrix library to be independent of other libraries. Also, I made it a simple code so that the compiler generates efficient code. Please try it out.

-- Reply to this email directly or view it on GitHub: https://github.com/sasagawa888/eisl/issues/307#issuecomment-2016330365 You are receiving this because you modified the open/close state.

Message ID: @.***>

sanjayjain159 commented 6 months ago

compiled routine matrix.o is fast when checked by mult op on 5x5 floating point matrix, which is of order n^3.

On 23 March 2024 9:07:57 AM IST, kenichi sasagawa @.***> wrote:

I have rewritten the matrix library to be independent of other libraries. Also, I made it a simple code so that the compiler generates efficient code. Please try it out.

-- Reply to this email directly or view it on GitHub: https://github.com/sasagawa888/eisl/issues/307#issuecomment-2016330365 You are receiving this because you modified the open/close state.

Message ID: @.***>

sanjayjain159 commented 6 months ago

I think there is difficulty in matrix-inverse also. Could it be that both matrix-det and matrix-inverse have some confusion in type of number float vs int?

On 23 March 2024 9:07:57 AM IST, kenichi sasagawa @.***> wrote:

I have rewritten the matrix library to be independent of other libraries. Also, I made it a simple code so that the compiler generates efficient code. Please try it out.

-- Reply to this email directly or view it on GitHub: https://github.com/sasagawa888/eisl/issues/307#issuecomment-2016330365 You are receiving this because you modified the open/close state.

Message ID: @.***>

sanjayjain159 commented 6 months ago

for integer

sanjayjain159 commented 6 months ago

I further tried (setq x1 #2a((1 2 3) (4 5 6) (7 8 9)). Here matrix-det gave the error not a number at ROUND NIL. Det should always be floating point, I think.

sanjayjain159 commented 6 months ago

Dear Sir, Pls cancel my previous 5 nessages. The matrix.o is working satisfactorily and it is fast. My previous examples were ill chosen with det equal to zero. Now I am satisfied mult, matrix-det and matrix-inverse are working nicely. The matrix I chose now is ((9 7 8) (3 2 1) (5 4 6)) and here the correct answers are obtained. Thank you.

sasagawa888 commented 6 months ago

I compiled and tested the rewritten Matrix. It encountered errors in specific data cases. Converting the data to float resolved the issue. The root cause is not yet understood.

sanjayjain159 commented 6 months ago

Sorry, I was simplistic when I ignored the difference between various types of numbers. Incidentally, is it possible to get the software to treat, in number arithmetic expressions, all types of numbers at par? For example, I think your introduction of quaternions is very nice and I believe they are also numbers in the sense they obey ordinary arithmetic rules. Also I noticed in Common Lisp and Scheme an expression such as (sin 1.0i) is valid and it allows to express in ordinary complex variable notation, this is quite interesting. Is that not possible in ISLisp?

sasagawa888 commented 6 months ago

In ISLisp, only integers and floating-point numbers can be handled. In Easy-ISLisp, integers are categorized into small integers and bignums. On the other hand, Common Lisp also allows the use of fractions and complex numbers. ISLisp has a minimal specification and may be more suitable for educational purposes rather than practical use. Implementing complex numbers by oneself could be beneficial for understanding mathematics. What one seeks in Lisp, and what goals one sets for oneself, will lead to different choices. I find the merit of ISLisp in the depth of understanding it offers through self-implementation. To parse complex numbers in the form of 1+2i, one would need to rewrite the parser, a feature that ISLisp lacks. I believe finding enjoyment within such constraints is also part of the pleasure of programming.

sanjayjain159 commented 6 months ago

Thank you for the clarification.