Jump to content



Photo

Project: Cplua


  • Please log in to reply
858 replies to this topic

#281 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 - 10:11 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 :)

I saw it in your announcement of version 0.72. Good work too. What else has been changed in memory management?

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 ;)

Grrr, indeed, you should have warned me :profanity:.
I hope that, in the new matrix library (or whatever solution you are working), A=B will work as it should, if A and B are matrices ;)

#282 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 - 10:33 PM

What else has been changed in memory management?

For example, a chunk that has been loaded and that is not in use (that means, there is no reference to its content) is unloaded, even if it needs to be called again later. It takes a little more time to load, but the memory gain is important :)

I hope that, in the new matrix library (or whatever solution you are working), A=B will work as it should, if A and B are matrices ;)

Well... no. :(
Simply because when you write "A=B" in Lua, you create a new variable A that overrides any older definitions of this variable, and thus you cannot know if A was a matrix or not. It is possible to know that B is a matrix, but that would mean that each time you allocate a variable (of any type), the interpreter must check if the given value if a matrix or not, and if it's the case, it must perform a copy. Unfortunately, this would greatly slow down the entire execution. <_<

What I suggest is one of Matlab's solution; if A and B are 2D matrices, than
A[:][:] = B[:][:]
would make a complete copy. I cannot use exactly the same syntax, but I suggest the following:
A['a']['a'] = B['a']['a'] -- 'a' for "all" rows or columns
Naturally, this works also for a single dimension:
A[0]['a'] = {1,2,3} -- write {1,2,3} in the first column
And there is no problem to use "extended matrices" with any number of dimensions :)

#283 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 - 10:49 PM

What I suggest is one of Matlab's solution; if A and B are 2D matrices, than

A[:][:] = B[:][:]
would make a complete copy.

Actually, this is Fortran's solution, copied in Matlab, and many other mathematical packages. Why not to copy it in CPLua ;). In case you don't know it, you can also say
A[1:2][4:5]
which means rows 1-3, columns 4 and 5. This is a very easy way to extract part of a matrix.
You can even use
A[1:9:2][:]
which means rows form 1 to 9, stepping by 2 (rows 1,3,5,7,9), any column.

I cannot use exactly the same syntax, but I suggest the following:

A['a']['a'] = B['a']['a'] -- 'a' for "all" rows or columns
Naturally, this works also for a single dimension:
A[0]['a'] = {1,2,3} -- write {1,2,3} in the first column
And there is no problem to use "extended matrices" with any number of dimensions :)

Looks ok to me. But what about a range of rows or columns, as in the examples I wrote before? Furthermore, I don't understand the zero index. The first row or column will be numbered as 0 by default?

#284 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 - 10:56 PM

In case you don't know it, you can also say

A[1:2][4:5]
which means rows 1-3, columns 4 and 5. This is a very easy way to extract part of a matrix.
You can even use
A[1:9:2][:]
which means rows form 1 to 9, stepping by 2 (rows 1,3,5,7,9), any column.

That's right, I forgot about that (I didn't use Matlab for a long time :P). I don't know if I will be able to do exactly the same in CPLua though :unsure: I will try to find a workaround ;)

Furthermore, I don't understand the zero index. The first row or column will be numbered as 0 by default?

Hmm, this is C vs Fortran again <_<
For me it's quite logical to start at index zero (it is also a bit easier to implement :lol: ), but this is not the case of everyone... Well, since CP Basic's matrices and CPLua's tables start at index 1, I think I should do the same with the "mat" package. ;)

EDIT: In case you didn't see it, I suggested a syntax for the mask in matrices operations in the last post of the previous page. What's your opinion about it?

EDIT2: Another subject: did you try the table.foreach function on CPLua 0.72 's "cas" package again to see the available CAS functions? :greengrin:

#285 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 - 11:12 PM

:idea:
What about this? :)

FORTRAN => CPLua
A[:][:] = B[:][:] => A[{}][{}] = B[{}][{}]
A[1][:2] => A[1][{2}]
A[1:2][4:5] => A[{1,2}][{4,5}]
A[1:9:2][:] => A[{1,9,2}][{}]
A[1][3:] => A[1][{1,3}}


#286 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 03 October 2005 - 09:12 AM

What about this? :)

FORTRAN => CPLua
A[:][:] = B[:][:] => A[{}][{}] = B[{}][{}]
A[1][:2] => A[1][{2}]
A[1:2][4:5] => A[{1,2}][{4,5}]
A[1:9:2][:] => A[{1,9,2}][{}]
A[1][3:] => A[1][{1,3}}

Looks nice to me, except for the second and last cases: In Fortran
A[1][:2]
means "first row, columns from the first to the second" (equivalent to A1[1:2]). If A1[{2}] will mean the same in CPLua, no problem (but see below for an alternative).
The last case seems to be "erroneous". In Fortran,
A[1][3:]
means "first row, columns from the third to the last one". Judging from the previous examples, the proposed CPLua form, A1[{1,3}], means "first row, columns 1 to 3", which is totally different.
An idea: implementing "from the n-th row/column to the last one" can be written as [{n,"e"}], where "e" stands for "end". For example,
A[1][{3,"e"}]
may be used for "first row, columns from the third to the last one".
Similarily, implementing "from the first row/column to the n-th" can be writen as [{"s",n}], where "s" stands for "start". For example,
A[1][{"s",4}]
may be used for "first row, columns from the first one to the fourth", and, according to your proposals, it is equivalent to
A[1][{1,4}]
Using A1[{"s",4}] or A1[{1,4}] instead of A1[{4}] seems to be more clear and self-explanatory.

#287 Orwell

Orwell

    Casio Overlord

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

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 03 October 2005 - 03:51 PM

Oops, I inverted the 2 statements :blush:

Naturally, I meaned
A[1][:2] => A[1][{1,2}]
A[1][3:] => A[1][{3}}
I think there should'nt be any confusion with this syntax ;)

But maybe I will accept the "e" and "s" indexes too as optional arguments :)

#288 Orwell

Orwell

    Casio Overlord

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

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 05 October 2005 - 04:58 PM

Okay I just finished the basis part of the "mat" package. :)
  • You can create matrices (arrays) of any size and dimension, and extract any smallest part of it:
  • A = mat(3,3) -- creates a blank 3*3 matrix
    A[1][1], A[1][2], A[1][3] = 1,2,3 -- first row = {1,2,3}
    print(A) -- prints "{{1,2,3},{0,0,0},{0,0,0}}"
    print[1][{}] -- prints the first row: "{1,2,3}" 
    B = mat(10) -- creates a vector of 10 elements
    print(B) -- prints "{0,0,0,0,0,0,0,0,0,0}"
  • You can create references to an existing matrix or duplicate it:
    B = A -- changing B's content will affect A's content too
    C = mat(A) -- A and C are independant
  • Conversion from Lua tables is also possible:
    A[1][{}] = {1,2,3} -- first row = {1,2,3}, with better syntax;)
    A[{}][{}] = {{1,2,3},{4,5,6},{7,8,9}}
    A[{1,2}][{2,3}] = {{1,2},{3,4}}
    print(A) -- prints "{{1,1,2},{4,3,4},{7,8,9}}"
    Note that writing
    A = {{1,2,3},{4,5,6},{7,8,9}}
    is incorrect, since this is the creation of a simple Lua table, called "A". However, writing
    A = mat(3,3, {{1,2,3},{4,5,6},{7,8,9}} )
    will create the 3*3 matrix "A" with the table's values :)
  • You can use "s" and "e" as indices to specify the first and the last element of a dimension.
    If "A" is a 3*5 matrix, writing
    A[{'s',2}][{4,'e'}]
    is the same as writing
    A[{1,2}][{4,5}]
  • The matrices may contain nil values.
    A = mat(10)
    mat[{1,3}] = 1
    mat[{4,6}] = nil
    mat[{7,10}] = {1,2} -- same as mat[{7,10}] = {1,2,nil,nil}
    print(A) -- prints "{1,1,1,nil,nil,nil,1,2,nil,nil}"
I will now start implementing some useful functions to manipulate it easily. PAP suggested the following functions: maxval,maxloc,minval,minloc, and sum. Do you think about any other functions? :D

For those functions it will be possible to use a mask and specify the dimension. However I cannot reproduce the exact Fortran syntax for masks, thus I suggest the following notation:
mat.maxval(A, MASK("<",3) )
instead of
maxval(A,A<3)
I know it is a bit heavy but I cannot do anything I want ;)

Btw: the maxloc (and minloc) function must return the coordinates of the max (or min) value in the matrix (which dimension is N). But should it be a lua table with N elements, or an array with N elements, or N individual values? :unsure:

#289 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 05 October 2005 - 07:20 PM

Okay I just finished the basis part of the "mat" package. :)
You can create matrices (arrays) of any size and dimension, and extract any smallest part of it:

A = mat(3,3) -- creates a blank 3*3 matrix
A[1][1], A[1][2], A[1][3] = 1,2,3 -- first row = {1,2,3}
print(A) -- prints "{{1,2,3},{0,0,0},{0,0,0}}"
print[1][{}] -- prints the first row: "{1,2,3}" 
B = mat(10) -- creates a vector of 10 elements
print(B) -- prints "{0,0,0,0,0,0,0,0,0,0}"

Everything seems to be ok, except that print1[{}] is a typo: you obviously wanted to write print(A1[{}]).
Btw, the fact that you can print a matrix by using a simple print is much better that the "table: hex number" you get with Lua tables.

You can create references to an existing matrix or duplicate it:

B = A -- changing B's content will affect A's content too
C = mat(A) -- A and C are independant

The fact that A=B will still create a pointer, instead of a real copied matrix, is a potential source of errors, but we will learn how to live with it...

Conversion from Lua tables is also possible.

Btw conversion from a matrix to a normal Lua table will be useful too.

Note that writing

A = {{1,2,3},{4,5,6},{7,8,9}}
is incorrect, since this is the creation of a simple Lua table, called "A". However, writing
A = mat(3,3, {{1,2,3},{4,5,6},{7,8,9}} )
will create the 3*3 matrix "A" with the table's values :)

Yes, but writing
A=mat(3,3)
A[{},{},{}] = {{1,2,3},{4,5,6},{7,8,9}}
will be fine, I hope.

You can use "s" and "e" as indices to specify the first and the last element of a dimension.
If "A" is a 3*5 matrix, writing

A[{'s',2}][{4,'e'}]
is the same as writing
A[{1,2}][{4,5}]

Excellent. Thanks.

The matrices may contain nil values.

A = mat(10)
mat[{1,3}] = 1
mat[{4,6}] = nil
mat[{7,10}] = {1,2} -- same as mat[{7,10}] = {1,2,nil,nil}
print(A) -- prints "{1,1,1,nil,nil,nil,1,2,nil,nil}"

Hmm, another typo. "mat" should be replaced by "A". Obviously, this is a "copy-paste-and-forget-to-modify-copied-text" error ;)

I will now start implementing some useful functions to manipulate it easily. PAP suggested the following functions: maxval,maxloc,minval,minloc, and sum. Do you think about any other functions? :D

Yes! there are plenty of them, and most of them can be easily implemented. Here are 3 more functions I was forced to write in Lua recently:
MatIdent(n): creates an identity matrix or rank n,
MatMul(A,C): multiplies two matrices, (matrix multiplication, not multiplying element by element).
MatTrans(A): transposes a matrix.
See the documentation of LuaNumAn 1.30 for details.
There are more useful functions that can be rather easily added, but I think that we should first test a version with those functions supported.

For those functions it will be possible to use a mask and specify the dimension. However I cannot reproduce the exact Fortran syntax for masks, thus I suggest the following notation:

mat.maxval(A, MASK("<",3) )
instead of
maxval(A,A<3)
I know it is a bit heavy but I cannot do anything I want ;)

Excellent. The syntax is a little bit longer, but that doesn't matter. What really matters is that masking will be possible now.

Btw: the maxloc (and minloc) function must return the coordinates of the max (or min) value in the matrix (which dimension is N). But should it be a lua table with N elements, or an array with N elements, or N individual values? :unsure:

I think that they should return something of the same type as their argument, i.e., a matrix with N elements.

A question: If I remember well, you said that simple "element-by-element" operations will be the most easy part. That means that we can also use parts of matrices to such operation? For example, an expression such as
C=A[{1,3}]+B[{6,8}]
will be valid? (C will be a matrix with 3 elements: C1 will be A1+B6, and so on). Tell me "yes, of course", please :huh:.

Overall, excellent work. By adding some matrix-related functions we will have, (at last!) decent matrix support in CPLua.

#290 Kilburn

Kilburn

    Casio Technician

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

  • Calculators:
    FX-7500 G
    ClassPad 300

Posted 05 October 2005 - 07:35 PM

Some suggestions for the environment:
For the program editor, make a text edit box which can expand horizontally as in Dev-C++
Or if it is not possible, please remove the line-wrapping, it can sometimes matter.

When an error occured make the program go to the line where the error occured.

Add Replace and Search commands.

Overwrite mode doesn't work if you press a key on the hard keyboard.

Add a catalog (you can include it as a menu item, it popups a combo box at the cursor location, and the you can choose your function).

And you could add word completion...

For the functions:

On the French forum, I said how to sound a buzzer. And on the CPSDK Forum, I and you said how to use the internal clock and how to set the contrast. You can implement these functions in CPLua, it would be great! :greengrin:


And how can I convert a string into an expression? cas.expr() doesn't work! :cry:

_____________________________
CPBasic is REALLY rotten... Use C++, Lua or Fortran 95 ! :lol2:

#291 Orwell

Orwell

    Casio Overlord

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

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 05 October 2005 - 08:14 PM

Sorry for the typo's, I was in a hurry ;)
There will be a better documentation later.

The fact that A=B will still create a pointer, instead of a real copied matrix, is a potential source of errors, but we will learn how to live with it...

I can't help that :(

Btw conversion from a matrix to a normal Lua table will be useful too.

Yessir B)

Yes, but writing

A=mat(3,3)
A[{},{},{}] = {{1,2,3},{4,5,6},{7,8,9}}
will be fine, I hope.

A=mat(3,3)
A[{}][{}] = {{1,2,3},{4,5,6},{7,8,9}}
is fine ;)
Unfortunately we can only write a single value (of any type) when indexing something... I had thought about using parenthesis instead, but "A(1) = 2" is not accepted :(

Yes! there are plenty of them, and most of them can be easily implemented. Here are 3 more functions I was forced to write in Lua recently:
MatIdent(n): creates an identity matrix or rank n,
MatMul(A,C): multiplies two matrices, (matrix multiplication, not multiplying element by element).
MatTrans(A): transposes a matrix.
See the documentation of LuaNumAn 1.30 for details.

No problem.

There are more useful functions that can be rather easily added, but I think that we should first test a version with those functions supported.

Sounds good for me :)

A question: If I remember well, you said that simple "element-by-element" operations will be the most easy part. That means that we can also use parts of matrices to such operation? For example, an expression such as

C=A[{1,3}]+B[{6,8}]
will be valid? (C will be a matrix with 3 elements: C1 will be A1+B6, and so on). Tell me "yes, of course", please :huh:.

"Yes, of course" ;)
i didn't mention that because it is not implemented yet. But don't worry this is my next planned job :)

For the program editor, make a text edit box which can expand horizontally as in Dev-C++
Or if it is not possible, please remove the line-wrapping, it can sometimes matter.

Hmm... The line-wrapping is rather useful, I'm not sure that removing it would be a good idea. Maybe I could make this option available however ;)

When an error occured make the program go to the line where the error occured

This is not easy... I'll see what I can do.

Add Replace and Search commands
Add a catalog (you can include it as a menu item, it popups a combo box at the cursor location, and the you can choose your function).
And you could add word completion...

I will soon have to hire a whole programmers team :lol2:

On the French forum, I said how to sound a buzzer. And on the CPSDK Forum, I and you said how to use the internal clock and how to set the contrast. You can implement these functions in CPLua, it would be great! :greengrin:

It would but these are still "gadgets"... there are other priorities ;)

#292 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 05 October 2005 - 10:02 PM

"Yes, of course" ;)
i didn't mention that because it is not implemented yet. But don't worry this is my next planned job :)

Yeaaaaaah :roflol:
Too bad that I will probably not be here when a version supporting the "mat" type will be released. All the next week I will be away from home (in fact, thousands of kilometers away). I will visit the so-called "ville-lumiere", also known as "Paris" ;). During this trip, my internet access will be sporadic at most...

Or if it is not possible, please remove the line-wrapping, it can sometimes matter.

For god's sake, leave the line-wrapping as it is. I agree that scrolling horizontally will be useful sometimes, but don't remove line wrapping!

When an error occured make the program go to the line where the error occured

Excellent idea. I was afraid even to ask for this, since I can imagine that it will be really difficult.

It would but these are still "gadgets"... there are other priorities ;)

Indeed. Nice gadgets, but gadgets.

#293 2072

2072

    Casio over god

  • Admin
  • PipPipPipPipPipPipPipPip
  • 1550 posts
  • Gender:Male
  • Location:Somewherebourg
  • Interests:Cinema, Programming, Music and a lot of thing...

  • Calculators:
    AFX2 ROM 1.02, CFX-9940GT+, FX-180P-Plus

Posted 05 October 2005 - 11:37 PM

All the next week I will be away from home (in fact, thousands of kilometers away). I will visit the so-called "ville-lumiere", also known as "Paris" ;) . During this trip, my internet access will be sporadic at most...



Eh bien bon s?jour ? Paris ! ;)

#294 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 06 October 2005 - 11:12 PM

Eh bien bon s?jour ? Paris ! ;)

Merci. A bientot!

#295 unique33

unique33

    Casio Freak

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

  • Calculators:
    classpad 300 , fx5500

Posted 10 October 2005 - 06:43 PM

try this:
print(cas.lim("log((x-2)/(x+2))","x",-2,1))

how to define infinity ?
print(cas.lim("1/x","x",cas.infinity))

#296 Orwell

Orwell

    Casio Overlord

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

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 10 October 2005 - 06:45 PM

The "inf" variable has been defined as the "infinite" expression. So you can write this:
cas.lim("1/x","x",inf)
;)

print(cas.lim("log((x-2)/(x+2))","x",-2,1))

You receive a "blank" result because this expression seems to be incorrect (try it in the Main mode); normally you should see an error message, but this wasn't completely implemented in CPLua 0.72 yet :rolleyes:

#297 unique33

unique33

    Casio Freak

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

  • Calculators:
    classpad 300 , fx5500

Posted 10 October 2005 - 07:21 PM

yeah
excuse me I had a mistake !

#298 unique33

unique33

    Casio Freak

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

  • Calculators:
    classpad 300 , fx5500

Posted 13 October 2005 - 05:56 PM

Have you implemented the with operator ?

(e1)|(e2)

for example :
sin(x)|x=Pi/4

#299 Orwell

Orwell

    Casio Overlord

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

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 13 October 2005 - 06:18 PM

It is implemented, and in fact this is what CPLua uses to evaluate an expression
For example if you write f = cas("sin(x)"); print(f(pi/4)) it will evaluate sin(x)|x=pi/4 ;)

#300 Kilburn

Kilburn

    Casio Technician

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

  • Calculators:
    FX-7500 G
    ClassPad 300

Posted 16 October 2005 - 12:21 PM

CPKeyboardManager is normally unsupported, no? So how could you make a .exe?

#301 Orwell

Orwell

    Casio Overlord

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

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 16 October 2005 - 01:53 PM

It's not because this class is unsupported that it is not available :)
It seems like you are a bit confused about the "unsupported" things; this does not mean that things don't work, but simply that Casio don't wish us to use them because it is too complex, or because it requires a lot of documentation to understand how to use it properly, or because it will maybe change in the future (like for the buzzer) etc ;)

#302 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 16 October 2005 - 10:13 PM

For me it's quite logical to start at index zero (it is also a bit easier to implement :lol: ), but this is not the case of everyone... Well, since CP Basic's matrices and CPLua's tables start at index 1, I think I should do the same with the "mat" package. ;)

In Fortran, you can define a matrix (or vector) with indices starting from any arbitrary integer (even negative), somewhat like Pascal's implementation. For example, you can define a vector "A" with 11 elements, from A[-5] to A5. But this is rather rarely used, so starting with A1 is OK as well. Of course, It will be nice if the "mat" package will be able to define matrices like Fortran or Pascal, but this is not really crucial, although it will be useful sometimes.

EDIT2: Another subject: did you try the table.foreach function on CPLua 0.72 's "cas" package again to see the available CAS functions? :greengrin:

Waiting for the "mat" package, I decided to stop implementing anything in LuaNumAn, because, when this package will be available, I will modify most of the numerical methods currently implemented. In other words, it's a good time for me to test the "cas" package...
The last day before my trip, I tried to modify the "Krone" library: it currently needs the first and second derivatives of a given function. I tried to make the derivatives automatically computed by using the cas.diff function. It worked for the first derivative, but I failed trying to compute the second derivative this way. I even got a "fatal exception error" :huh:. However, I'm not exactly sure on what was wrong (my program or the "cas" package itself). Nevertheless, the fatal exception error I got signals that something is wrong (even if my program was completely wrong, I should not get a calculator hang). I'm planning to reproduce that fatal error in the next few days, and, more generally, to test the CAS capabilities in CPLua. Unfortunately, this will take sometime, since, just after my return, I have found plenty of things that I must do (nobody takes 7 days of vacations for free :().

#303 Orwell

Orwell

    Casio Overlord

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

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 16 October 2005 - 11:37 PM

Hmm okay if you can reproduce this bug then let me know how it happens. The fatal exception error may come from the CAS functions of the SDK itself, because they will simply crash the calculator if they are not correctly used <_<

The "mat" package is almost ready. Here is the list of the currently available functions:
maxval/minval // optional mask and dimension available 
maxloc/minloc // optional mask available 
sum // optional mask and dimension available 
new // creates a new matrix of any size and dimension (same as 'calling' the mat table directly)
ident // create an identity matrix of specified size
trans // returns the transposed matrix of a 2D mat
det // computes the determinant of a 2D matrix using Gauss's algorithm
invert // returns the inverted matrix of a 2D mat
system // solves a linear system using Gauss's algorithm (default implementation)
systGauss // idem
systTriUp // solves an upper triangular system
systTriLow // solves a lower triangular system
totable // conversion from a matrix to a table

Naturally, the arithmetic and indexing operations on matrices are supported as well ;)

I will wait another release before adding new functions, so we will take time to test these ones correctly before completing the package. (I was though thinking about implementing the LU decomposition, just by curiosity to compare the speed with PAP's LUDecompose function written in Lua and using basic tables :))

However I don't know yet if the next version of CPLua will be 0.73 or 0.8... There is an important modification that I want to do for the next major release (but it only concerns the internal structure of the add-in, it shouldn't have any visible consequences), thus I will perhaps let you test the "mat" package while I'm performing those changes ;) Note that there will certainly be a "release candidate" version before any next official release :rolleyes:

#304 unique33

unique33

    Casio Freak

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

  • Calculators:
    classpad 300 , fx5500

Posted 17 October 2005 - 12:20 PM

by with operator , I mean this :
consider this in main :
((x-a)/(x+a))|(x-a)=|x-a|
result:
|x-a|/(x+a)

also consider this :
f=cas("x^2")
print(f(a))

"a" is a variable and no value is assigned to it !
can you define a new variable type for example a cas.VAR or something like this ?
which does not have nill value by default ?

#305 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 17 October 2005 - 01:50 PM

det // computes the determinant of a 2D matrix using Gauss's algorithm
systGauss // idem

Hmmm, not enough information is given. What kind of Gauss elimination have you used? with partial pivoting, with total pivoting, or with no pivoting at all? Please, tell me that you used pivoting, partial or total...


Naturally, the arithmetic and indexing operations on matrices are supported as well

Wow. I want to test this. It will eliminate the need of loops :).


(I was though thinking about implementing the LU decomposition, just by curiosity to compare the speed with PAP's LUDecompose function written in Lua and using basic tables :))

You can just transfer the code in LUDecompose to C ;). It will be certainly faster then. Note that basic tables will be eliminated in the next version of LuaNumAn, since I will replace all tables with "mat" matrices ;). However, I don't know if using the "mat" package extensively will make the program execution faster :unsure:.

I will perhaps let you test the "mat" package while I'm performing those changes ;) Note that there will certainly be a "release candidate" version before any next official release :rolleyes:

Yes, you do that ;). Release version 0.73, with the "mat" package supported! If you do so, I will be able to modify everything in LuaNumAn, and this will be a great test for the "mat" package.

#306 Orwell

Orwell

    Casio Overlord

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

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 17 October 2005 - 05:19 PM

by with operator , I mean this :
consider this in main :

((x-a)/(x+a))|(x-a)=|x-a|
result:
|x-a|/(x+a)

Writing
f = cas("((x-a)/(x+a))|(x-a)=abs(x-a)")
print(f)
in CPLua returns the following result:
abs(x-a)/(x+a)
;)


also consider this :

f=cas("x^2")
print(f(a))
"a" is a variable and no value is assigned to it !
can you define a new variable type for example a cas.VAR or something like this ?
which does not have nill value by default ?

I'm not sure of what you're trying to do :huh:
You cannot use undefined variables in CPLua like you use them in the Main mode (that means, if you use a name that has not been defined before, it will never be considered as a cas variable).
However, you can write a=cas("a") to manipulate the 'a' variable, like in
a=cas("a");
f = a^2;
print( f(a,2) ) -- evaluates f(a) with a=2
This other code is equivalent:
f = cas("a^2");
print( f("a",2) ) -- evaluates f(a) with a=2

There is currently no easy way to access the real CAS variables, lists, matrices etc. I will try to find a more suitable method later ;)


Hmmm, not enough information is given. What kind of Gauss elimination have you used? with partial pivoting, with total pivoting, or with no pivoting at all? Please, tell me that you used pivoting, partial or total...

Well, since I'm not an expert in numerical analysis I just used the only kind of Gauss elimination I know :unsure: What are the main differences between total and partial pivoting? :)

#307 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 17 October 2005 - 10:24 PM

Well, since I'm not an expert in numerical analysis I just used the only kind of Gauss elimination I know, What are the main differences between total and partial pivoting?

Pivoting in Gauss elimination (and in LU decomposition) is mandatory, because without pivoting these methods often give totally wrong results, due to roundoff errors. In a computer program, you must use pivoting in Gauss elimination, or you risk to get totally erroneous results! Both total and partial pivoting prevent roundoff errors efficiently. Total pivoting is somewhat faster than partial pivoting, but not much. Forthermore, implementing partial pivoting is much easier than total pivoting. For these reasons, in practice, partial pivoting is used even in professional applications, while total pivoting is rarely used. But nobody uses a computer program implementing these methods without pivoting at all: it is very-very-very dangerous.
Ehm, if you like, I can write a Lua implementation of Gauss elimination, then you can translate it to C. I didn't included such a method in LuaNumAn because LU decomposition is 3 times faster than Gauss elimination in solving systems of linear equations. I think that the best way to proceed is to forget Gauss elimination, and use LU decomposition both for computing the determinant of a matrix and to solve systems of linear equations. In fact, Gauss elimination is very useful only for analytic computations; in Numerical Analysis, it is teached as an introductory numerical method in the subject, since it is the simplest method, but it is almost never used in practice.

Btw, if you are interested, the best book that I know about numerical methods is this:
J.-P. Nougier, Methodes de calcul numerique (volumes 1 & 2), Hermes Science Publications, 2001 (www.hermes-science.com).
This book gives plenty of details for each numerical method; it also gives examples of use and algorithms (in pseudocode). It is written in french, but obviously this is not a problem for you (as for me ;)).
The well known best-seller in Numerical Analysis called Numerical Recipes (www.nr.com) is good as well, but it does not explain details, and it gives ready Fortran or C programs that are not really structured, at least in my opinion.

#308 Orwell

Orwell

    Casio Overlord

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

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 17 October 2005 - 11:39 PM

That still doesn't tell me what you mean by 'pivoting' :lol:
I could implement the LU decomposition as well, I just used the Gauss elimination because I needed a "default" method to compute a determinant or to invert a matrix... But I do not plan to write some other more complicated methods of numerical analysis myself, I will give the possibility to anyone to write it (in Lua or in C++) ;)

#309 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 18 October 2005 - 09:38 AM

That still doesn't tell me what you mean by 'pivoting' :lol:

In short: partial pivoting is rearranging rows before each Gauss elimination step, so that the maximum absolute value element in the "current" column will be the "pivot", i.e., the leading element (the element at the diagonal of the matrix). Total pivoting is rearranging rows and columns before each Gauss elimination step, so that the maximum absolute value element in the whole matrix will be the "pivot". I know that this short explanation doesn't explain much, but it is really difficult to explain the whole theory about pivoting here. See any good book on Numerical Analysis for details.
In any case, you should never use Gauss elimination in a computer program without pivoting; it is catastrophic. In University Matrix Algebra courses, pivoting is not even mentioned, because it is not needed, if you do Gauss elimination "by hand". But in a computer program, pivoting is mandatory, so every course in Numerical Analysis gives emphasis on pivoting. Copied from the book I mentioned in my previous post:
Il n'est pas necessaire d'optimiser les pivots dans les deux ca suivants: (1) la matrice est symetrique definie positive, (2) la matrice est a diagonale dominante. Dans tous les autres cas, il est necessaire d'optimiser les pivots. En pratique, une optimisation partielle sera dans la grande majorite des cas suiffisante.
I bet my ClassPad that you will not find any book in Numerical Analysis saying that pivoting is not mandatory in computer programs.

I could implement the LU decomposition as well, I just used the Gauss elimination because I needed a "default" method to compute a determinant or to invert a matrix...

Hmmm, even in LU decomposition, pivoting is mandatory. Furthermore, I have to warn you that Gauss elimination is not the "default" method to compute a determinant or to invert a matrix, because it is the slowest one.

But I do not plan to write some other more complicated methods of numerical analysis myself, I will give the possibility to anyone to write it (in Lua or in C++) ;)

Well, as you know, this is already a work in progress; it's my LuaNumAn project. A chacun son domaine ;).

#310 Orwell

Orwell

    Casio Overlord

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

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 18 October 2005 - 12:02 PM

Hmm, it seems that the method I used won't be enough then :(
Like you said, "A chacun son domaine". I will let those functions empty for now, and ask someone who's more competent than myself to write them in C++ (with all the needed information of course) ;)
Though I think that those "default" methods like mat.invert, mat.det, mat.system are really important in the mat package. I'm sure that most people will be glad to use matrices and to be able to use some common functions like 'det' to get the determinants, even if they don't know how complex it could be. I don't want to force them to use a "specialized" library like LuaNumAn for such """simple""" operations, because I think that they will just get more confused. However naturally LuaNumAn will stay a very good tool for anyone who want to go farther than the default features of the mat package ;)

PS: Note that it is easy for me to define a C function that just executes some "hard-coded" Lua instructions, thus if you want (and if you have time for it...) you could decide the more suitable way to implement those default methods, then write it in Lua, and I will encapsulate your code in a C function, as a temporary version :) Naturally it won't be as fast as the equivalent code written in C++, but it will perhaps be easier to convert it later :rolleyes:

#311 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 18 October 2005 - 12:21 PM

I will let those functions empty for now, and ask someone who's more competent than myself to write them in C++ (with all the needed information of course) ;)

I think I can do that, if you want. I'm not an experienced C++ programmer (and I will probably never be), but implementing these methods is not that difficult, if you know the underlying theory...

Though I think that those "default" methods like mat.invert, mat.det, mat.system are really important in the mat package. I'm sure that most people will be glad to use matrices and to be able to use some common functions like 'det' to get the determinants, even if they don't know how complex it could be. I don't want to force them to use a "specialized" library like LuaNumAn for such """simple""" operations, because I think that they will just get more confused. However naturally LuaNumAn will stay a very good tool for anyone who want to go farther than the default features of the mat package ;)

Totally agree.

if you want (and if you have time for it...) you could decide the more suitable way to implement those default methods, then write it in Lua, and I will encapsulate your code in a C function, as a temporary version :) Naturally it won't be as fast as the equivalent code written in C++, but it will perhaps be easier to convert it later :rolleyes:

It's already done in Lua ;). Just use the "LUdecomp" file in LuaNumAn for this. Note, however, that this library will be modified, as soon as the "mat" package will be available.

#312 unique33

unique33

    Casio Freak

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

  • Calculators:
    classpad 300 , fx5500

Posted 19 October 2005 - 08:34 AM

consider this :
f=cas("x^2+y^2")
print(f("x",2,"y",2))

is it possible to evaluate a function which have more than one variable ?

also consider this :

f=cas("lim(a*b*1/x,"x",1)")
print(f("a",1,"b",3))


#313 Orwell

Orwell

    Casio Overlord

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

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 19 October 2005 - 12:25 PM

consider this :

f=cas("x^2+y^2")
print(f("x",2,"y",2))
is it possible to evaluate a function which have more than one variable ?

Not yet. I already thought about it though, so I will try to find a way ;)

also consider this :

f=cas("lim(a*b*1/x,"x",1)")
print(f("a",1,"b",3))

Be careful, you are mixing the native CAS instructions and their adaptations in CPLua again :(
You may call any native CAS function like this, but you may not add quotes inside some other quotes.
Thus you can use one of the following syntaxes for example:
f=cas("lim(a*b*1/x,x,1)")

or

f=cas.lim("a*b*1/x","x",1)

or

a=cas("a")
b=cas("b")
x=cas("x")
f=cas.lim(a*b*1/x,x,1)
Unfortunately "f("a",1,"b",3)" is not accepted for now. Maybe later ;)

#314 Orwell

Orwell

    Casio Overlord

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

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 21 October 2005 - 09:52 PM

It's time for some news :)

The 'mat' package should now be ready for CPLua 0.73.
Here is the updated list of the available functions:
maxval/minval // optional mask and dimension available 
maxloc/minloc // optional mask available 
sum // optional mask and dimension available 
new // creates a new matrix of any size and dimension (same as 'calling' the mat table directly)
ident // create an identity matrix of specified size
trans // returns the transposed matrix of a 2D mat
det // computes the determinant of a 2D matrix using LU decomposition
invert // returns the inverted matrix of a 2D mat
solve // solves a linear system using LU decomposition
systTriUp // solves an upper triangular system
systTriLow // solves a lower triangular system
totable // conversion from a matrix to a table
resize // resizes a matrix
size // returns the size of each dimension of a matrix
sizedim // returns the size of the specified dimension of a matrix
dim // returns the numbers of dimension

About the 'mat.det' and 'mat.solve' functions: I finally took PAP's LUdecom code, and converted it in C++. ;)

To test the 'mat' package I made it compute the determinant (and the invert matrix) of a 10*10 matrix.
Here are the results I got for the determinant's calculation:
- using the CP Main mode: 1 time in ~5'00 sec   => 5'00s
- using CPLua's 'cas' package: 1 time in ~4'80 sec => 4'80s
- using PAP's LUdecom program: 100 times in ~23'00 sec => 0'23s
- using the 'mat.det' function: 500 times in ~7'30 sec => 0'00146s (:p)
- using PAP's program but with the 'mat' package: 10 times in ~5'00 sec => 0'50s.
And a few comments about it:
- the CAS has the same speed in the main mode or in CPLua's 'cas' package; it just took a little more time in the Main mode to update the screen with this big matrix :rolleyes:
- PAP's program works really good :lol:
- and its C++ translation rocks B)
- but unfortunately, the same Lua program is slower with matrices than with simple Lua tables. :(

This last comment is actually a normal consequence: it is impossible to create a customized type in Lua which usage would be faster than a built-in type like tables... This is the price for the additional features provided by the matrix objects :/
Note that it is already quite faster than with the previous versions of the 'mat' package; I spent a lot of times to see how I could optimize the 'index' operation to increase its speed when we want to access one or several elements of a matrix, so unfortunately I think I won't be able to do better than that. I suppose that we will have to live with it...

You should be able to try it yourself this week-end ;)

#315 CrimsonCasio

CrimsonCasio

    UCF Ambassador

  • [Legends]
  • PipPipPipPipPipPipPipPipPipPip
  • 3579 posts
  • Gender:Male
  • Location:USA
  • Interests:Claculators, Stephen King, Video Games, Calculators, Programming, Calculators, Reading, Calculators... hmm, what else... Ah! Calculators!

  • Calculators:
    Algebra FX2.0, CFX 9850Ga+, Classpad 300

Posted 22 October 2005 - 02:46 AM

im having some problems with the following code, and its leading me to wonder if its supported or not:

lists={{1,{1,2,3},{1,2,3}},{2,{1,2,3},{1,2,3}}}
lists11 // returns 1
lists112 // should return 2, gives error.

any time i go over 2 pairs of [] it stops working, im not sure if im just screwing up or if this just isnt supported... :(

edit:

ok... now im having a weirder problem:

ii=(stage[stage.y][stage.x]-3)*10 //ive been able to determine that this is the problem, it returns 1 but it doesnt =1 ???
print(ii) // prints 1

if ii==1
Then print("done") //this never prints
end


if i add ii=1 right above the if then it works... i have no idea why.
:'(

edit again:

found workarounds for all of this, but i still dont understand why they arent working >_>

#316 Orwell

Orwell

    Casio Overlord

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

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 22 October 2005 - 09:17 AM

lists={{1,{1,2,3},{1,2,3}},{2,{1,2,3},{1,2,3}}}
lists11 // returns 1
lists112 // should return 2, gives error.

Well if lists11 is the number 1, then lists112 is certainly incorrect... (it's like you were trying to access the 2nd element of the number 1) However, lists12 should return a table with {1,2,3}, and so lists122 will return 2.

ii=(stage[stage.y][stage.x]-3)*10 //ive been able to determine that this is the problem, it returns 1 but it doesnt =1 ???
print(ii) // prints 1

if ii==1
Then print("done") //this never prints
end
if i add ii=1 right above the if then it works... i have no idea why.

This is rather strange, but I need to see how your "stage" table is structured to find where the problem could be...

#317 CrimsonCasio

CrimsonCasio

    UCF Ambassador

  • [Legends]
  • PipPipPipPipPipPipPipPipPipPip
  • 3579 posts
  • Gender:Male
  • Location:USA
  • Interests:Claculators, Stephen King, Video Games, Calculators, Programming, Calculators, Reading, Calculators... hmm, what else... Ah! Calculators!

  • Calculators:
    Algebra FX2.0, CFX 9850Ga+, Classpad 300

Posted 23 October 2005 - 12:08 AM

stage contains intergers ranging from -1 to 99, the particular spot i was looking at will always contain a value from 3.1 to 3.9. i made a somewhat less effecient workaround for what i needed, but it seems the act of subtracting or multiplying caused the weirdness (as i was printing all sorts of things trying to figgure out what was happening, and as soon as i removed the math it worked, even though its using the same numbers)

as for the 3d array, i did mean lists122, but any attempt to use more than 2 sets of brackets was giving me an attempt to access a nil cell (or something like that).

im having a new problem now. stage is a huge array, loaded from an external file. durring the course of play changes are made to stage. when you finish the current stage you currently return to the main menu and can re-select the stage (currently theres only 1). the problem is, even though the stage should be initiallized each time you start the game, after the first time you play (untill you break execution) the stage does not reset. ive tried multiple ways to reset the stage (doscript, various functions, etc) but nothing works. i know its getting to the point where the stage is initialized (debug print), but it fails to load the original version of the stage. i even had stage=nil then re-initialized it for the same result. im not sure why this should be or how i can fix it...

i'll upload what parts of this i have working in just a sec so you can take a look at it if you want.

edit: link: http://crimsoncasio....PLua/runner.zip (this is a remake-in-progress of one of my AFX basic games)

btw, here's what stage looks like: (some line breaks inserted for conveinance)

A=3.1
B=3.2
o=99
stage={
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,1,0,0,B,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,1,2,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,2,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,2,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,2,0,0,0,0,0,o,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,2,0,0,0,0,0,0,o,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0},
{0,0,0,0,0,0,2,0,0,0,0,0,0,o,0,0,0,0,0,0,0,0,0,4,0,1,0,0,0,0,0,0},
{0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0},
{0,0,0,0,0,0,2,0,0,0,0,0,0,o,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,2,0,0,0,0,0,0,o,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,o,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,o,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,1,1,2,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,1,1,0,0,0,0,0,0,0,0},
{0,0,X,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,A,0,2,0,0,0,0,0,0,0,0,0,0},
{0,1,1,2,1,0,2,0,0,0,0,0,0,0,0,0,0,0,0,1,1,2,0,0,0,0,0,0,0,0,0,o},
{0,0,0,2,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,o,0,0,0,0,0,1},
{0,0,0,2,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,o,1},
{0,0,0,2,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,o,1,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}}

stage.x and .y are set later, the represent the position of the character on the map (PLR.X, .Y represent his position on the screen)

#318 Orwell

Orwell

    Casio Overlord

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

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 23 October 2005 - 11:29 AM

I'm currently looking at your code. Here are some remarks:

* In the file "stage1", you wrote
stage = {}
(...)
stage.x = 0
stage.y = 0
stage = {{ ... }}
This is not really correct. By writing this last line you erase the old 'stage' table and replace it by another table containing the "map"; that means that the 'stage' table does not contain the 'x' and 'y' fields anymore. If you try to read them you will get a nil value. Maybe this is the cause of the weird things you have seen ;)

* About the initialization of the 'stage' table: Note that tables' content is never implicitely copied.
It seems like this is a problem with global and local variables. In your file "stage1" the table 'stage' is global to the chunk (and not attached to the function 'map.Load'), so this is allways the same table that will be used. For your case I suggest that you write something like this:

///////// File "Runner/stage1":

function init()
  local stage = { {...}, test=1 }
  return stage
end

export{initStage=init}

///////// File "Runner/stage2":

function init()
  local stage = { {...}, test=2 }
  return stage
end

export{initStage=init}

//// you should create some other files "stage3", "stage4" etc

///////// File "Runner/lib":

do
  local current  -- an interesting trick :)
 
  function loadStage(i)
	if current~=i then
	-- print("loading stage "..i)
	doscript("Runner/stage"..i)
	current=i
	end
	return initStage
  end
end

export{loadStage=loadStage}

///////// File "Runner/Runner":

require "Runner/lib" -- syntax OK too
...
stageOrder = {1,2,3,3,2,2,4, n=7} -- for example only :p

for i = 1,stageOrder.n do
  initStage = loadStage(stageOrder[i])
  ...
  for j=1,3 do
	stage = initStage()
	print(stage.test)
	stage.test = stage.test+1
	...
  end
end
I've tested it and it should work fine :)
Btw, we already discussed with PAP that the runnable scripts should not export symbols; but in that case I think it was more convenient. I think that I will give the possibility to scripts to simply return the symbols they want to export, so here a better code would be 'initStage=doscript("Runner/stage"..i)' instead of an implicit exportation of the 'initStage' function.

#319 CrimsonCasio

CrimsonCasio

    UCF Ambassador

  • [Legends]
  • PipPipPipPipPipPipPipPipPipPip
  • 3579 posts
  • Gender:Male
  • Location:USA
  • Interests:Claculators, Stephen King, Video Games, Calculators, Programming, Calculators, Reading, Calculators... hmm, what else... Ah! Calculators!

  • Calculators:
    Algebra FX2.0, CFX 9850Ga+, Classpad 300

Posted 23 October 2005 - 01:57 PM

ok, i get what your saying, i'll try that out.

i never have a problem with the .x and .y though because i re-create it later, the stuff at the top is mostly for my refrence (and some because i just dont know enough about the language yet :P)

#320 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 23 October 2005 - 03:51 PM

It's time for some news :)

Indeed. It's time for some good news!

About the 'mat.det' and 'mat.solve' functions: I finally took PAP's LUdecom code, and converted it in C++. ;)

Glad to know that I helped. I hope that the inverse matrix is computed via LU decomposition too.

- the CAS has the same speed in the main mode or in CPLua's 'cas' package; it just took a little more time in the Main mode to update the screen with this big matrix :rolleyes:

This is natural. Even Mathematica needs noticeably more time, if a large result is printed.

- PAP's program works really good :lol:

Well, thanks. I'm trying to make my programs as robust as I can, but, of course, they can always be improved.

- and its C++ translation rocks B)

Of course it rocks. It's a translation of a good program, and it has been translated by a good programmer ;).

- but unfortunately, the same Lua program is slower with matrices than with simple Lua tables. :(
This last comment is actually a normal consequence: it is impossible to create a customized type in Lua which usage would be faster than a built-in type like tables... This is the price for the additional features provided by the matrix objects :/
Note that it is already quite faster than with the previous versions of the 'mat' package; I spent a lot of times to see how I could optimize the 'index' operation to increase its speed when we want to access one or several elements of a matrix, so unfortunately I think I won't be able to do better than that. I suppose that we will have to live with it...

Actually, I was expecting such a behavior. For the explanation of the increased computation time, I couldn't say it better than you: a custom type is by nature slower than a built-in one. But this is nothing, concerning the new possibilities that are now available. Furthermore, the "mat" package will make all matrix-related codes clearer and shorter :). Afterall, your tests show that it's still much faster than matrix calculations in the "Main" application.

You should be able to try it yourself this week-end ;)

yes, yes, yes! :roflol:




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users