Jump to content



Photo

Project: Cplua


  • Please log in to reply
858 replies to this topic

#241 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 27 September 2005 - 09:08 AM

Eeeek! I just found another source of crashes :banghead:
Fortunately I already corrected it. But for now, avoid to edit more than 2 files at the same time!!
CPLua 0.72 is in preparation <_<

orwell: yon can perhaps add a a function to measure execution time (cf http://www.cpsdk.com...wtopic.php?t=63) even if it's not real time units, that could be usefull ;)

Thanks, I will think about that ;)

#242 PAP

PAP

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 681 posts
  • Gender:Male
  • Location:Somewhere in Europe.
  • Interests:Computer Algebra, Numerical Analysis.

  • Calculators:
    ClassPad 300 (plus an old Casio model, with only a few Kb ram).

Posted 27 September 2005 - 09:19 AM

I did, and I must say that I was impressed :bow:

Well, thanks. Your work about CPLua is much more impressive, despite the lack of documentation. :)
Actually, I'm not quite satisfied by the current documentation of LuaNumAn. I'm planning to add a full explanation for each driver program, and details about the examples solved there. But this needs a lot of time, plus I don't know if someone will ever read it :(.

I know that I will have to write a decent documentation for CPLua, but I don't know if I will go that far :lol2:

Maybe I can write the documentation for CPLua, if you want ;). Not technical details, of course, since I don't know much about it; just a function list, its explanation, and some examples. But I'm not quite sure that it is a good idea: it will need coordination, and the developer always knows more than the user.

#243 PAP

PAP

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 681 posts
  • Gender:Male
  • Location:Somewhere in Europe.
  • Interests:Computer Algebra, Numerical Analysis.

  • Calculators:
    ClassPad 300 (plus an old Casio model, with only a few Kb ram).

Posted 27 September 2005 - 09:42 AM

CPLua 0.72 is in preparation <_<

Ehm, since you are preparing a new version, there are some functions that will be extremely useful, and they can be easily implemented. Think about:

C=table.column(A,col): Extracts the col-th column of a matrix A. Returns nil if A is not a 2D-matrix, or if col is not within permitted range. Examples:
C=table.column({{1,2,4},{7,6,-2}},3) returns C={4,-2}.
C=table.column({1,2,3},3) returns C=nil.
C=table.column({1,2,{4,5},7,3},1) returns C=nil.
C=table.column({{1,2,4},{7,6,-2}},4) returns C=nil.

i,m=table.maxloc(A): returns the position, i, and the value, m, of the maximum element of a vector (or a 2D-matrix) A. The returning variable i is a vector containing the incides {row,column} of the maximum value. It should return nil if A is not a vector or a 2D-matrix. Examples:
table.maxloc({1,2,3,7,5}) returns i={1,4} and m=7.
table.maxloc({{1,2,4},{7,6,-2}}) returns i={2,1} and m=7.
i,m=table.maxloc({1,2,{4,5},7,3}) returns i=nil, m=nil.

i,m=table.minloc(A): As table.maxloc, but locates the minimum value.

Of course, all these functions can be written in Lua itself (I did it already), but a built-in implementation will be faster and more convenient. Perharps it makes more sense to add these functions in a new library called "matrix", since they are not operating on every table, only on matrices. We have already discussed about such a library; I have proposed more complex (but also useful) functions for it. The functions I post now, however, can be easily implemeted.

#244 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 27 September 2005 - 10:35 AM

That's right, I think that a "matrix" package will be more convenient :nod:
I will try to set its basement :)

Btw, I tried to check the available memory before any new allocations, but CPWindow::MemoryCheck(size,false,false) allways returns 'true' and I still got an error popup when the ClassPad runs out of memory :huh:

#245 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 27 September 2005 - 06:52 PM

Sorry I didn't work on the matrix package today, because there are already several things that I want to finish before that... :unsure:

But well, I didn't lost my time neither, and guess what? :P

The CAS is now completely supported! :nod:
All functions of the Main mode are now available. You can even work with lists or matrices etc :D

Here are some small examples of Lua code using it:
f = cas("3*e^(x/2)+sin(x)")
print( cas.diff( f, "x", 2) )
print( "f(3)= ".. f(3) )

m = cas("[[1,2][3,4]]")
print("The determinant of " .. m .. " is " .. cas.det(m) )

print("The primitive of 1/x is " .. cas.integ("1/x") )

A last point: there are several functions that do not use a litteral name in the Main Mode, but rather a mathematical symbol or a Greek letter. I need to choose a name for them, since we cannot enter those symbols in the editor. "integ" is fine for the indefinite integration, but for example I cannot use "prod" and "sum" for the corresponding symbols since there are other functions that already use those names (for list manipulation) <_<
Perhaps I could choose "Prod" and "Sum", but this could lead to confusion. Any suggestion? :)

#246 PAP

PAP

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 681 posts
  • Gender:Male
  • Location:Somewhere in Europe.
  • Interests:Computer Algebra, Numerical Analysis.

  • Calculators:
    ClassPad 300 (plus an old Casio model, with only a few Kb ram).

Posted 27 September 2005 - 08:47 PM

But well, I didn't lost my time neither, and guess what? :P
The CAS is now completely supported! :nod:
All functions of the Main mode are now available. You can even work with lists or matrix etc :D

W - O - W :beer: :lmao: :bow:
Indeed, you didn't lost your time! With the CAS implemented, CPLua becomes totally unbeatable!

A last point: there are several functions that do not use a litteral name in the Main Mode, but rather a mathematical symbol or a Greek letter. I need to choose a name for them, since we cannot enter those symbols in the editor. "integ" is fine for the indefinite integration, but for example I cannot use "prod" and "sum" for the corresponding symbols since there are other functions that already use those names (for list manipulation) <_<
Perhaps I could choose "Prod" and "Sum", but this could lead to confusion. Any suggestion? :)

I think that the ultimate solution to avoid confusion is to use a self-explanatory name for all CAS literals, and to add the prefix "CAS_" to all of them, even if there is no Lua function with a similar name. Maybe it should be useful to add such a prefix in all CAS functions, e.g., "CAS_integ", "CAS_diff" etc. Afterall, most CAS functions have names that, quite likely, can be used by a naive user as Lua variables, because their names are usually self-explanatory, and everybody wants to name the variables with names that identify their use. It is likely that a user may decide to define a variable named "integ", but it will probably never define such a variable as "CAS_integ".
For the Greek letters, we can perharps use the common english spelling such as "epsilon", "gamma", "nu", "omega", etc. (I can help on this, if you don't know how Greek letters are usually spelled in english ;)). But I think that, even in this case, the prefix "CAS_" should be added, since Greek letters are sometimes used as user variables. For example, "epsilon" is a common name for a variable storing the number that added to 1 leads to something more than 1. In general, Greek letters are extensively used in mathematics, and a programmer may want to name a variable with a Greek letter, if the corresponding quantity is usually symbolized this way.
Adding the prefix "CAS_" to every CAS function and Greek letter has only one drawback: the names will become longer, and you have to tap more keys. But this is nothing, compared to the elimination of confusion with Lua functions or common user names for variables. Afterall, Mathematica uses a similar convention: all functions have large names.
Maybe a shorter prefix will more convenient. But someone may have a better solution to this problem.

#247 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 27 September 2005 - 08:51 PM

About the "CAS_" prefix: well by looking at my examples you could see that each function begins with "cas." since you need to use this table to access it ;)

OK for Greek letters, but what about "pi"? :P
I already overloaded the "pi" constant with an appropriate expression (and not value)... and there is the "Pi" (product) function too :lol:

Edited by 2072, 28 September 2005 - 04:39 AM.


#248 unique33

unique33

    Casio Freak

  • Possibly hacked
  • PipPipPipPip
  • 229 posts
  • Gender:Male
  • Location:Iran

  • Calculators:
    classpad 300 , fx5500

Posted 27 September 2005 - 09:17 PM

Is it possible to have write.table and read.table functions ?
I think it is useful for huge computations .
I recieved the Insufficient error message because of huge computation on tables.

for example:
x={}
for i=1,4500 do
x[i]=1000
end

instead we can have :

x={}
for i=1,4500 do
write.table(x[i]=1000) -- write the elements of the table in a temporary file
end

for i=1,4500 do
local x
x=read.table(x[i])
print(x)
end

If it is implemented so far in another way , please explain about it . thanks .



A last point: there are several functions that do not use a litteral name in the Main Mode, but rather a mathematical symbol or a Greek letter. I need to choose a name for them, since we cannot enter those symbols in the editor. "integ" is fine for the indefinite integration, but for example I cannot use "prod" and "sum" for the corresponding symbols since there are other functions that already use those names (for list manipulation) <_<
Perhaps I could choose "Prod" and "Sum", but this could lead to confusion. Any suggestion? :)

maybe case Sensibility would be usefull , you can write all of these functions by Uppercase

#249 PAP

PAP

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 681 posts
  • Gender:Male
  • Location:Somewhere in Europe.
  • Interests:Computer Algebra, Numerical Analysis.

  • Calculators:
    ClassPad 300 (plus an old Casio model, with only a few Kb ram).

Posted 27 September 2005 - 09:19 PM

About the "CAS_" prefix: well by looking at my examples you could see that each function begins with "cas." since you need to use this table to access it ;)

I noticed the "cas.", I just thought that if a program requires, e.g., the "table" library you cannot use variables such as "copy" because there is a function named "table.copy". I now realized that this is not true, so there is no confusion. My bad, forget the prefix.

OK for Greek letters, but what about "pi"? :P
I already overloaded the "pi" constant with an appropriate expression (and not value)... and there is the "Pi" (product) function too:lol:

Obviously, we should use "Pi" or "Sigma" for prod and sum, since ClassPad uses these capital letters for these functions. Indeed "pi" and "Pi" may be confusing, but we can live with this. Afterall, Lua is a case-sensitive language.

#250 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 27 September 2005 - 09:19 PM

Is it possible to have write.table and read.table functions ?
I think it is useful for huge computations .

There is currently no way to do that... :(
But actually, the tables are not really appropriate for this kind of use.
I think I will try to add a better array support, together with matrices ;)

Edit: Btw, you are not allowed to do that in the Main mode neither =)

#251 unique33

unique33

    Casio Freak

  • Possibly hacked
  • PipPipPipPip
  • 229 posts
  • Gender:Male
  • Location:Iran

  • Calculators:
    classpad 300 , fx5500

Posted 27 September 2005 - 09:43 PM

I'm not quite satisfied by the current documentation of LuaNumAn. I'm planning to add a full explanation for each driver program, and details about the examples solved there. But this needs a lot of time, plus I don't know if someone will ever read it :(.


Do not foget me , maybe I,m not a programmer , I,m a user , but certainly I will use your programs and the documentations , as I mentioned so far :)

you are very good teachers for me , I alwayes want to have friends like you : PAP , Orwill,... :)
but I do not have in reality :(

#252 PAP

PAP

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 681 posts
  • Gender:Male
  • Location:Somewhere in Europe.
  • Interests:Computer Algebra, Numerical Analysis.

  • Calculators:
    ClassPad 300 (plus an old Casio model, with only a few Kb ram).

Posted 27 September 2005 - 11:15 PM

Do not foget me , maybe I'm not a programmer , I,m a user , but certainly I will use your programs and the documentations , as I mentioned so far :)

I didn't forgot you, afterall you are currently the only one that asked something about how those programs work. But you are wrong: you are not an ondinary user (if you was, you will not be interested on CPLua). You already wrote Lua programs, even numerical methods. Maybe your programs are not the best it can be, but you started programming, and this is a great step: you will become a better and better programmer, just keep trying. Don't underestimate yourself. Nobody was born a good programmer.
I don't want to sound like a teacher, but I think that the best rule for learning programming is this: never accept a program written by someone else blindly, even if he is the best programmer in the world. Always try to find out why the program is written as it is, and try to answer questions such as "why he wrote this function this way?" or "why not to modify this function, so that it will be more flexible?". Try to write your own implementation, and try to write it as general and functional as it gets. You will probably fail in the beginning, but you will learn plenty of things.

Btw, your idea about saving a large matrix is already implemented in some large mathematical packages: they have a function named "fprintfMat" (or something similar), which saves a matrix into a file, then you can open this file, and read only a part of the saved matrix. But, for ClassPad, this is rather exaggerating. You can do many useful things in CPLua without such a facility.

#253 PAP

PAP

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 681 posts
  • Gender:Male
  • Location:Somewhere in Europe.
  • Interests:Computer Algebra, Numerical Analysis.

  • Calculators:
    ClassPad 300 (plus an old Casio model, with only a few Kb ram).

Posted 27 September 2005 - 11:26 PM

I think I will try to add a better array support, together with matrices ;)

Yes! Yes! You do that! I have many proposals about functions for matrix support. I already posted some of them, and, believe me, I have many-many others to propose too.
Btw, the CAS is not a solution to the poor matrix support in Lua, because, unfortunately, ClassPad's CAS has not a decent matrix support; it is just a little less primitive than Lua's built in "tables": you can transpose a matrix, or compute its inverse, but you cannot even compare two matrices: if A and C are matrices, judge(A=C) is not valid :(.

#254 unique33

unique33

    Casio Freak

  • Possibly hacked
  • PipPipPipPip
  • 229 posts
  • Gender:Male
  • Location:Iran

  • Calculators:
    classpad 300 , fx5500

Posted 28 September 2005 - 12:06 AM

I changed the footers of Programming in Lua (Ebook) which was so ugly before :(
If anyone want it for print , It looks better now .

#255 PAP

PAP

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 681 posts
  • Gender:Male
  • Location:Somewhere in Europe.
  • Interests:Computer Algebra, Numerical Analysis.

  • Calculators:
    ClassPad 300 (plus an old Casio model, with only a few Kb ram).

Posted 28 September 2005 - 06:59 AM

I changed the footers of Programming in Lua (Ebook) which was so ugly before :(
If anyone want it for print , It looks better now .

I wanted to ask you to do this, if you have time, but you did it already. Undeed they look much better now. Thanks! :)
There is, however, a problem if you try to print it: the margins are too small, so it is almost impossible to bind the printed version as a book. Is it possible to make the margins larger? I'm planning to overpass this problem by printing the pdf with the option "Shrink oversized pages to paper size" enabled in Acrobat, but maybe there is a better solution.
Btw, is it possible to make the font used somewhat smaller, in order to reduce the total number of pages?

#256 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 28 September 2005 - 04:09 PM

Hmm, I spent a little time on the web to find a suitable C++ matrix class with the kind of functions you want, but it's not that easy :(
I think that the most interesting package is this one. However, CPLua will grow by 150 to 200 Kb at least with this lib, and well, this is a little too big ;)

I think I will have to work on this library myself :rolleyes:

#257 PAP

PAP

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 681 posts
  • Gender:Male
  • Location:Somewhere in Europe.
  • Interests:Computer Algebra, Numerical Analysis.

  • Calculators:
    ClassPad 300 (plus an old Casio model, with only a few Kb ram).

Posted 28 September 2005 - 06:28 PM

Hmm, I spent a little time on the web to find a suitable C++ matrix class with the kind of functions you want, but it's not that easy :(
I think that the most interesting package is this one. However, CPLua will grow by 150 to 200 Kb at least with this lib, and well, this is a little too big ;)
I think I will have to work on this library myself :rolleyes:

This package is really reach; I especially liked the fact that simple operators (+,-,*,/) are defined to work even with matrices (such operators, plus many other matrix-related things, do exist in Fortran 95 only :greengrin:). But you are right, this package is a little bit huge for ClassPad, plus there is no need to add all things included in the package. Matrix operators will be very useful though; I don't know if it can be implemented without a great headache, but, if it can, it will considerably reduce the need for loops, and it will be much faster.
The best way to proceed is the "do it yourself" way. If you need any help or suggestion, I'm here (I really know Matrix Algebra, Numerical Analysis is full of matrices).

Btw, working in the new CPLua environment is a real pleasure :).

#258 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 28 September 2005 - 06:53 PM

This package is really reach; I especially liked the fact that simple operators (+,-,*,/) are defined to work even with matrices (such operators, plus many other matrix-related things, do exist in Fortran 95 only :greengrin:).

In fact this is the easiest part of the work... Any matrix library should at least provides the operators for their new matrix type (In C++, you can override any operator to work with any type :greengrin:). But actually I absolutely don't need that in CLua, since the C++ code will barely never performs arithmetic operations on the matrices: they will be used only once in the functions corresponding to Lua operators but that's all ;) I still have to create the Lua operators for matrices myself :rolleyes: (but this isn't difficult ;) )

Btw, working in the new CPLua environment is a real pleasure :).

If you think about some new convenient things, you know where to post them ;)

#259 PAP

PAP

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 681 posts
  • Gender:Male
  • Location:Somewhere in Europe.
  • Interests:Computer Algebra, Numerical Analysis.

  • Calculators:
    ClassPad 300 (plus an old Casio model, with only a few Kb ram).

Posted 28 September 2005 - 07:30 PM

In C++, you can override any operator to work with any type :greengrin:).

Iknow that, but if you see how easy is to redifine any operator to work on any type (or mixed types) in Fortran 95, you will never want to do it in C++ again :greengrin:.

But actually I absolutely don't need that in CLua, since the C++ code will barely never performs arithmetic operations on the matrices: they will be used only once in the functions corresponding to Lua operators but that's all ;) I still have to create the Lua operators for matrices myself :rolleyes: (but this isn't difficult ;) )

I'm afraid that I don't exactly understand. You are planning to define operators for matrices in a Lua function? it will be slow then.

If you think about some new convenient things, you know where to post them ;)

I know, it's the place I post almost everyday ;).

#260 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 28 September 2005 - 07:32 PM

I'm afraid that I don't exactly understand. You are planning to define operators for matrices in a Lua function? it will be slow then.

:huh: Did you think about anything else? :unsure:

#261 unique33

unique33

    Casio Freak

  • Possibly hacked
  • PipPipPipPip
  • 229 posts
  • Gender:Male
  • Location:Iran

  • Calculators:
    classpad 300 , fx5500

Posted 28 September 2005 - 09:55 PM

I wanted to ask you to do this, if you have time, but you did it already. Undeed they look much better now. Thanks! :)
There is, however, a problem if you try to print it: the margins are too small, so it is almost impossible to bind the printed version as a book. Is it possible to make the margins larger? I'm planning to overpass this problem by printing the pdf with the option "Shrink oversized pages to paper size" enabled in Acrobat, but maybe there is a better solution.
Btw, is it possible to make the font used somewhat smaller, in order to reduce the total number of pages?


I use adobe acrobat professional 6
maybe this can help :

file -> print ->printer section
( you can choose between Adobe PDF printer or Microsoft Office Ducument Image Writer ,
you should choose Adobe PDF printer)

-> properties -> Layout -> Advanced -> graphic -> Scaling ( choose the proper scale here)

but about the font , I tryed to change it but I could not find such capability in Adobe Acrobat
I think scaling the document will solve the problem .
again I,m sorry because of 5 blank pages .
If I delete them I should change all of the Index references !
the University is started and mine is far from my home ( 600 kms ) , I do not have my pc now ! :(

There is currently no way to do that... :(
But actually, the tables are not really appropriate for this kind of use.
I think I will try to add a better array support, together with matrices ;)

Edit: Btw, you are not allowed to do that in the Main mode neither =)


ok. you are right but consider this :
x={}
for i=1,4000 do
x[i]=1000
end

it just take 1 second on classpad , so it,s not a huge operation .it just allocate huge memory .
maybe this allocating is nothing for a computer which have 512 or 1024 mb RAM
but for classpad it,s huge . so if you want to implement arrays I think impelementing some tools to use the Flash memory of classpad ( I mean the hard ) instead of RAM will be usefull.

#262 PAP

PAP

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 681 posts
  • Gender:Male
  • Location:Somewhere in Europe.
  • Interests:Computer Algebra, Numerical Analysis.

  • Calculators:
    ClassPad 300 (plus an old Casio model, with only a few Kb ram).

Posted 28 September 2005 - 10:51 PM

I think scaling the document will solve the problem .
again I,m sorry because of 5 blank pages .
If I delete them I should change all of the Index references !

It's ok as it is now, you did a nice job. Thanks for the information you provided, I'll try to scale the pages to, say, 85%.

if you want to implement arrays I think impelementing some tools to use the Flash memory of classpad ( I mean the hard ) instead of RAM will be usefull.

Great idea, but I'm afraid that it will be extremely difficult to implement. Futhermore, I don't know if the flash memory is fast enough for loading/ saving large amount of data there. Maybe Orwell can tell us something about it...

#263 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 29 September 2005 - 08:52 PM

Version 0.72 is out :)

It features several improvements and bug fixes. :rolleyes:
The crashes of the 0.7 and 0.71 versions should not appear again. There was also a bug with the frame of the window when using the graphic mode, and this has been fixed.

Other major modifications:
- Great improvement in the memory management. The garbage collector is now called periodically, and automatically. Of course this can slow down the execution a little bit, but it is really necessary and not quite noticeable ;) Plus, the memory space used when calling external chunks and libraries has been drastically lowered.
- A simple draw.pixel() function. This is the same as draw.point() but for a single pixel only and it is ~2.5 times faster ^_^
- (Almost) complete support of the CAS :P See the file "functions.txt" to know how to use it.

As allways, every comments are welcome :D

Great idea, but I'm afraid that it will be extremely difficult to implement. Futhermore, I don't know if the flash memory is fast enough for loading/ saving large amount of data there. Maybe Orwell can tell us something about it...

I don't think that this is currently possible. But the memory space used by Lua's tables can get really huge when the table contains a lot of elements (~500 and more). A simple C array will use quite less memory for the same thing ;)

#264 unique33

unique33

    Casio Freak

  • Possibly hacked
  • PipPipPipPip
  • 229 posts
  • Gender:Male
  • Location:Iran

  • Calculators:
    classpad 300 , fx5500

Posted 29 September 2005 - 09:25 PM

In your Integ sample program f:integ does not work but cas.integ(f) works as expected .

#265 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 29 September 2005 - 09:27 PM

In your Integ sample program f:integ does not work but cas.integ(f) works as expected .

D'oh <_< You're right, I forgot this sample. You should ignore it until next version ;)

#266 unique33

unique33

    Casio Freak

  • Possibly hacked
  • PipPipPipPip
  • 229 posts
  • Gender:Male
  • Location:Iran

  • Calculators:
    classpad 300 , fx5500

Posted 29 September 2005 - 09:36 PM

why Pong sample does not run as expected on the executable one ? It just write score=0 !

#267 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 29 September 2005 - 09:38 PM

why Pong sample does not run as expected on the executable one ? It just write score=0 !

Because the speed of the executable is quite higher than the speed of the real Add-In... It is so fast than you cannot play it :lol2:

#268 unique33

unique33

    Casio Freak

  • Possibly hacked
  • PipPipPipPip
  • 229 posts
  • Gender:Male
  • Location:Iran

  • Calculators:
    classpad 300 , fx5500

Posted 29 September 2005 - 09:41 PM

Because the speed of the executable is quite higher than the speed of the real Add-In... It is so fast than you cannot play it :lol2:

waww . you are right .
:lol2:
BTW: I could get 4 scores ! :lol:

#269 unique33

unique33

    Casio Freak

  • Possibly hacked
  • PipPipPipPip
  • 229 posts
  • Gender:Male
  • Location:Iran

  • Calculators:
    classpad 300 , fx5500

Posted 29 September 2005 - 10:07 PM

please explain more about cas.Sigma (cas.Pi)
what are the arguments?
Is it in this case : [i]cas.Sigma(f,n,a, b )
If it is possible give an example .

#270 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 29 September 2005 - 10:16 PM

Argh! I inverted the "Sigma" and "Pi" functions :banghead:
Indeed you should have some strange results right now :roflol:

Wait 5 minutes I will quickly upload a corrected version ;)

Edit: Okay it is better now, thanks ;)
I also corrected the Integ sample program.

The 'Sigma' function is the function "Σ(" in the main mode. It uses the same syntax.
For example you can write
sum = cas.Sigma("sin(x)/x","x",1,10)
to compute the sum of sin(x)/x for x taking entire values in [1,10]
Notice that this function needs strings or expressions as arguments. You can also write:
f = cas("sin(x)/x")
sum = cas.Sigma(f,"x",1,10)
Or even better:
x = cas("x")
sum = cas.Sigma( cas.sin(x)/x, x, 1,10)

There are still some problems because it is not that easy to obtain a simple real number from a CAS operation.
In this case for example, the result is "sin(10)/10+sin(9)/9+ ... + sin(1)" and not the exact value.
But this will be arranged it further versions :)

#271 unique33

unique33

    Casio Freak

  • Possibly hacked
  • PipPipPipPip
  • 229 posts
  • Gender:Male
  • Location:Iran

  • Calculators:
    classpad 300 , fx5500

Posted 29 September 2005 - 11:22 PM

should I download the dll file each time ?

#272 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 30 September 2005 - 07:38 AM

should I download the dll file each time ?

Naturally no, that's why there is only a link to it ;)

#273 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 30 September 2005 - 01:18 PM

PAP, and everyone here :), I need your opinion about this:

CPLua currently uses the "double" type as type for every numbers. This provides a great accuracy for mathematic operations, however it requires a lot of memory.
I'm thinking about changing this type into "float". The precision is naturally not as good, but it requires only the half of the memory space required by the "double" type (a float number takes 4 bytes, and a double number takes 8 bytes). If CPLua use this type, the available memory for the programs will be more than doubled. This is important, because Lua's operations and tables are heavy and, well, the ClassPad has not as much memory as a real computer ;)

Here is a screenshot of the results of the first example in PAP's "DKrone" program; "float" is used at the left side, and "double" at the right side.
Posted Image
As you can see, the "float" type is slightly less accurate than "double", but the precision isn't "too" bad (for common users I mean). Note that I don't exactly know if the results are the more accurate possible or if it can be increased (for example by doing more iterations), I just ran the DKrone program with each type.

What do you think about it? :unsure:

#274 rafapa

rafapa

    Newbie

  • Members
  • Pip
  • 14 posts
  • Location:Spain

Posted 30 September 2005 - 03:39 PM

PAP, and everyone here :), I need your opinion about this:

CPLua currently uses the "double" type as type for every numbers. This provides a great accuracy for mathematic operations, however it requires a lot of memory.
I'm thinking about changing this type into "float". The precision is naturally not as good, but it requires only the half of the memory space required by the "double" type (a float number takes 4 bytes, and a double number takes 8 bytes). If CPLua use this type, the available memory for the programs will be more than doubled. This is important, because Lua's operations and tables are heavy and, well, the ClassPad has not as much memory as a real computer ;)
.
.
.
.


What do you think about it? :unsure:


Need it to be hardwired? (Sorry if it has an obvious answer, I'm just starting with Lua coming from Fortran). I any case if it's not too difficult you could produce two versions of CPLua one with "double" and the other with "float" I presume that in some tricky cases the higher precision could be necesary.

#275 Kilburn

Kilburn

    Casio Technician

  • Members
  • PipPipPipPipPipPip
  • 491 posts
  • Gender:Male
  • Location:France
  • Interests:Blah

  • Calculators:
    FX-7500 G
    ClassPad 300

Posted 02 October 2005 - 12:02 PM

Great work! :greengrin:

I have some suggestions for you:
* draw.pxltest(x,y) : returns nil if the pixel at (x,y) is off, and true if it is on.
* draw.picture(x,y,path) : draws a picture
* clearconsole() : clears the console window

And for input(), you could make it display a text on the console window and put the input field after it.
You should also initialize the getkey() function when you start the program.
I think that's all. ;)

#276 PAP

PAP

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 681 posts
  • Gender:Male
  • Location:Somewhere in Europe.
  • Interests:Computer Algebra, Numerical Analysis.

  • Calculators:
    ClassPad 300 (plus an old Casio model, with only a few Kb ram).

Posted 02 October 2005 - 07:10 PM

PAP, and everyone here :), I need your opinion about this:

CPLua currently uses the "double" type as type for every numbers. This provides a great accuracy for mathematic operations, however it requires a lot of memory.
I'm thinking about changing this type into "float". The precision is naturally not as good, but it requires only the half of the memory space required by the "double" type (a float number takes 4 bytes, and a double number takes 8 bytes). If CPLua use this type, the available memory for the programs will be more than doubled. This is important, because Lua's operations and tables are heavy and, well, the ClassPad has not as much memory as a real computer ;)

...the "float" type is slightly less accurate than "double", but the precision isn't "too" bad (for common users I mean). Note that I don't exactly know if the results are the more accurate possible or if it can be increased (for example by doing more iterations), I just ran the DKrone program with each type.

What do you think about it? :unsure:

(Back again after a weekend away from computer)

It would be great if you can define in your program which precision you prefer, either globally (affecting all variables) or, more preferably, "per variable", i.e., defining if a specific variable is float or double (but the latter seems too dificult to implement).
There are many cases in Numerical Analysis where single precision (4 bytes) is catastrophic. In the "Dkrone" program, there is no problem in this case, i.e., for the function that DKrone uses as an example. But, in general, float instead of double will make many numerical methods in ClassPad almost unusable. On the other hand, memory saving is crucial: I had many problems this weekend, trying to implement a non-linear fitting method in CPLua: the program uses some tables of about 500 elements each, and ClassPad runs out of memory quickly. A temporary workaround I have found useful is to call the function collectgarbage() periodically in the program. This overpasses the problem, but only partially: it is not run out of memory too quickly. I will try version 0.72 to see if the new garbage collection system solves the problem, but the fact is that memory is limited, so in some cases float arithmetic, instead of double, will be really useful.
To conclude, I think that the best way to proceed is to make available in CPLua both float and double arithmetics. rapafa's idea of two separate CPLua versions for float or double support seems inconvenient to me. Is it possible to make the user able to choose between float and double?

PS: In the upcoming LuaNumAn version 1.3, you will find two new numerical methods. One of them is memory consuming, and it will be a great test for your idea of float arithmetics.

#277 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 02 October 2005 - 07:23 PM

(Back again after a weekend away from computer)

I was wondering what happened to you :lol:

Unfortunately, like rafapa already supposed it, the double or float type is "hardwired" in the interpreter, and it is completely impossible to change it at runtime. I don't think it would be possible to create a new type with double precision, because this type should be available in the matrices too etc :(
I think I will keep the double type for now.

Btw, I worked on the "mat" package this week-end, I wrote over a thousand lines of C++ code to implement the different functions that PAP suggested and it worked fine but... Well, I had a better idea. :P I decided to start again from zero with this package; it will take a little time, but I think you will like it :)

About garbage collection: you're right, calling collectgarbage() periodically is really useful; the version 0.72 does it for you now ;)

About Kilburn's suggestions:
- a draw.pxltest() function is easy to do, no problem :)
- I will try to create a complete packages for sprites, not only a single function ;)
- Well, there is the clear() function... :nod:

#278 PAP

PAP

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 681 posts
  • Gender:Male
  • Location:Somewhere in Europe.
  • Interests:Computer Algebra, Numerical Analysis.

  • Calculators:
    ClassPad 300 (plus an old Casio model, with only a few Kb ram).

Posted 02 October 2005 - 08:46 PM

I was wondering what happened to you :lol:

I was away, but with my ClassPad. I came back with CP filled with two more complex numerical methods, better plotting functions, and a (small) bug report (see below). <_<

I think I will keep the double type for now.

It's ok for me. Numerical Analysis is (almost) all about double precision. ;)

Btw, I worked on the "mat" package this week-end, I wrote over a thousand lines of C++ code to implement the different functions that PAP suggested and it worked fine but... Well, I had a better idea. :P I decided to start again from zero with this package; it will take a little time, but I think you will like it :)

Wow. You didn't lose your time either. Note that LuaNumAn now contains some more matrix-related utility functions (i was forced to write them for this weekend's developement):
MatIdent(n): returns the identity matrix of size nxn.
MatTrans(A): returns the matrix A transposed.
MatMul(B,C): Matrix (or vector) multiplication.
All of them can be implemented easily (MatMul is a little bit tricky, it needs to detect if an argument is a vector or a matrix). Maybe you will want to add these functions in the matrix library (if you didn't do it already). Note: the new version of LuaNumAn that includes them will be uploaded tomorrow (at least, I hope so - I need to write the documentation of the new numerical methods added this weekend).

About garbage collection: you're right, calling collectgarbage() periodically is really useful; the version 0.72 does it for you now ;)

Indeed, it does it, and it does it very well!. My non-linear fitting function hanged ClassPad in version 0.71, if you tried to use "large" data tables (more than 80 data points). Now it works very well with much larger tables, without even the need to call the function collectgarbage() explicitly. Several matrices of 300 elemnts each are not a problem anymore. Good work! :bow:

- a draw.pxltest() function is easy to do, no problem :)
- I will try to create a complete packages for sprites, not only a single function ;)

Bah, game-computing stuff :P. The sprite support will be interesting though (but not too much for me).

Bug in the table.copy function: this function works as expected only for vectors. It copies the table, but only on "level 1", i.e., only if the elements of the table are not tables. Elements in "level 2" or higher are not copied (the hated pointing system works instead). Consider the piece of code:
A={{1,2},{3,2}}
B=table.copy(A)
B[2][1]=4711
Now, if table.copy worked as expected, table A should remain unchanged, but, in fact, this is not true: element in 2nd row, first column of A is also changed to 4711, because the "copied" table A is actually a matrix: table.copy does not copy elements with type="table", it only uses pointers to them. So, if an element of B is modified, the corresponding element in A is modified as well. The obvious workaround is to use the following code, instead of a simple table.copy:
require("table")
A={{1,2},{3,2}}
B={}
for i=1,table.getn(A) do
 B[i]=table.copy(A[i])
end
B[2][1]=4711
It is, however, longer. Furthermore, the behavior of the function, as it is now, is a potential source of errors. Hopefully, it will be easy to eliminate this bug.
Note: it took me more than 2 hours to figure out what was happening in a program I was writing this weekend. I checked and rechecked everything in the algorithm, it was correct, but the results were wrong :(. The problem was the behavior of the table.copy function :cry:.

#279 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 02 October 2005 - 08:53 PM

Calling collectgarbage() periodically isn't the only improvement of memory mamagement in CPLua 0.72 ;) For example, the loaded chunks are quite lighter than before etc :)

You're right about table.copy; this is the way I wrote it. I should have warned you about that... sorry :unsure:
I'm working on another solution ;)

#280 Orwell

Orwell

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 777 posts
  • Gender:Male
  • Location:Paris - France

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 02 October 2005 - 09:07 PM

Btw, I tried to find a good solution for masks in matrix operations, but I couldn't find a better way than writing
mat.maxval(A, MASK("<",3) )
as equivalent to
maxval(A, A<3)
I know that it is a bit heavy, but well that's all I can do with Lua ;)


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users