Jump to content



Photo

Lua Language


  • Please log in to reply
39 replies to this topic

#1 girdeux

girdeux

    Casio Addict

  • Members
  • PipPipPip
  • 88 posts
  • Location:Spain / Castell?n

  • Calculators:
    casio fx-115ms;
    casio classpad 300

Posted 11 August 2006 - 12:23 PM

Can someone tell me if exists a document about the Lua language in Spanish?
If it exists, can you tell me the direction?
If it doesn't exist I try read in Inglish, but I'm not sure if then I will can program in CPLua... :unsure:
Thanks for all.

#2 omegavirus

omegavirus

    Casio Freak

  • Members
  • PipPipPipPip
  • 150 posts
  • Gender:Male
  • Location:Morelia, M?xico

  • Calculators:
    ClassPad 300

Posted 12 August 2006 - 06:17 AM

Can someone tell me if exists a document about the Lua language in Spanish?
If it exists, can you tell me the direction?
If it doesn't exist I try read in Inglish, but I'm not sure if then I will can program in CPLua... :unsure:
Thanks for all.


I have not seen any document in spanish I think only portuguese and english... :nonono:

#3 Tchernoben

Tchernoben

    Casio Fan

  • Members
  • PipPip
  • 42 posts
  • Location:Nice
  • Interests:Calculators, Pc, mangas, warhammer.

  • Calculators:
    Classpad 300
    Ti 89 Titanium

Posted 06 September 2006 - 01:19 PM

As far as I'm concerned, I've loked for books about Lua and I found NOTHING :)

Lua is'nt popular yet

#4 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 06 September 2006 - 02:54 PM

well you may try to search about World of Warcraft add-on programming since it uses LUA as scripting engine you may find good link to lua tutorials and even a lot of code example...

#5 Orwell

Orwell

    Casio Overlord

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

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 06 September 2006 - 06:09 PM

Just for information, this page shows a list of project that use Lua in their implementation. I guess there are more than you could think ;)

#6 girdeux

girdeux

    Casio Addict

  • Members
  • PipPipPip
  • 88 posts
  • Location:Spain / Castell?n

  • Calculators:
    casio fx-115ms;
    casio classpad 300

Posted 10 September 2006 - 03:59 PM

Ok I have decided to read the programming_in_Lua.pdf that you can find in the topic download CPLua by Orwell.

I have one simple question, in pag 14 of pdf named you can see:

-- defines a factorial function
function fact (n)

 --more lines

print("enter a number:")
a = io.read("*number") -- read a number
print(fact(a))

When I run this lines in my emulator, it shows me a error message, :angry: the problem is in io.read, I have to load the function? io.read is like an input?

In the file functions (is in the .rar when you download CPLua) I have found:

IO:
io.folder() + folder management:
fold:exists(), fold:create(), fold:remove(), fold:rename(),
fold:name(), fold:content()

io.file() + file management:
fi:exists(), fi:create(), fi:remove(), fi:rename(), fi:copy(),
fi:header(), fi:folder(), fi:name(), fi:size(), fi:open(),
fi:isopen(), fi:write(), fi:read(), fi:eof(),

What is this? What is the use of this file? It has the answer of my io.read problem? :blink: :blink:

Yes I'm starting in Lua. ;) Sorry for my novice questions.

#7 The_AFX_Master

The_AFX_Master

    Casio Overlord

  • Admin
  • PipPipPipPipPipPipPip
  • 519 posts
  • Gender:Male
  • Location:Black Mesa Research Facility (sector C)
  • Interests:BASIC +FORTRAN 90+ C++.....and HALF LIFE

  • Calculators:
    Casio Algebra FX 2.0 Plus, Casio fx 570 ms, Classpad 300, And a crowbar

Posted 10 September 2006 - 04:28 PM

Girdeux, IO package on CPLua is suitable to read external files (ie text).or files written by CPLua in some format. If you need to input numbers via prompt the user use var=input(str) where str (optional) is a string to be displayed in the input console line :D

#8 Orwell

Orwell

    Casio Overlord

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

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 10 September 2006 - 05:39 PM

The book "Programming in Lua" is good to discover the features and possibilities of the Lua language... However you must know that there are a lot of differences with the libraries and packages implemented in CPLua. In CPLua there is no function "io.read()", but instead you have a function "input()" that you could use to ask for a string or a number. The file "functions.txt" lists all the functions that are specific in CPLua ;)

I really need to write something for CPLua beginners... :unsure:

#9 The_AFX_Master

The_AFX_Master

    Casio Overlord

  • Admin
  • PipPipPipPipPipPipPip
  • 519 posts
  • Gender:Male
  • Location:Black Mesa Research Facility (sector C)
  • Interests:BASIC +FORTRAN 90+ C++.....and HALF LIFE

  • Calculators:
    Casio Algebra FX 2.0 Plus, Casio fx 570 ms, Classpad 300, And a crowbar

Posted 10 September 2006 - 05:49 PM

The book "Programming in Lua" is good to discover the features and possibilities of the Lua language... However you must know that there are a lot of differences with the libraries and packages implemented in CPLua. In CPLua there is no function "io.read()", but instead you have a function "input()" that you could use to ask for a string or a number. The file "functions.txt" lists all the functions that are specific in CPLua ;)

I really need to write something for CPLua beginners... :unsure:


sure. I can restart the tut that i begun some months ago. The forum needs a pinned FAQ for newbies, too many questions, the same questions.. i will start the topic now

#10 betoe

betoe

    UCF Spanish Translator

  • Admin
  • PipPipPipPipPipPipPip
  • 846 posts
  • Gender:Male
  • Location:Guadalajara/Mazatlan, Mexico.
  • Interests:Electronics, SW development, automotive. Swim->bike->run

  • Calculators:
    Algebra FX2.0 (R.I.P.), Classpad 300

Posted 10 September 2006 - 07:57 PM

I really need to write something for CPLua beginners...

I agree with that :), i think its needed. Hope the afx master could help you, its a lot of work for one person, to develop, make faqs etc...

#11 girdeux

girdeux

    Casio Addict

  • Members
  • PipPipPip
  • 88 posts
  • Location:Spain / Castell?n

  • Calculators:
    casio fx-115ms;
    casio classpad 300

Posted 13 September 2006 - 11:08 AM

--first with numbers
a=1
b=a
print(b) --> 1 ok
b=2
print(a) --> 1 ok

--now with tables
a={}
a[1]=1

b=a
--b is equal to a, but a should remain equal to 1 (for me) 

print(b[1]) --> 1 ok
b[1]=2
--now b=2, but a should remain equal to 1

print(a[1]) --> 2 not ok

someone can tell me why??
PD: I usually use matlab.

#12 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 13 September 2006 - 12:57 PM

Well, I had a similar question a long time ago, and I'm sure that you will be surprised by the answer: Unlike common intuition, if a is a table, b=a does not create a new table b; instead, it creates a pointer to a. Therefore, if you change b1, a1 is changed, since b1 simply points to a1 :huh:. I know it's strange and annoying, but this is how it works. Lua is similar to C/C++ in matrix handling; this means that it has very poor matrix support. Nevertheless, it can be used for writing math programs.

Fortunately, there is a solution: Orwell has added a very useful function in CPLua; it's called table.copy, and does what it is obvious from its name: b=table.copy(a) creates a new table b (not a pointer to a), so that changes in b don't affect a. Conclusion: use b=table.copy(a) instead of b=a (unless you want to create a pointer -- but usually you don't want such a thing).
Note that if a is a number, b=a does not create a pointer, but a new real variable b. That's why you don't see strange results in this case.

Btw, AFX_Master, you should add such an explanation to your CPLua tutorial.

PS: Matlab is good, but it's also an expensive commercial product; my opinion is to use Scilab or Octave instead.

#13 Orwell

Orwell

    Casio Overlord

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

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 13 September 2006 - 01:57 PM

A very delicate question indeed...

The problem is that you are viewing the Lua tables from the mathematical point of view (and it's perfectly normal, since you especially care about maths in your programs). You may not forget that math programs represent only a very small part of what you could do with a general-purpose programming language (like Lua). :)

Like I said before, tables and matrices exist (in different forms) in most decent languages. And in most cases (at least 80%), the programmer wants to be able to manipulate several references to the same table.
Create implicit copies of matrices would require a lot of time and memory, and most programmers won't need this feature and won't accept to lose time and memory for that. Thus, the default behaviour is that tables are not implicitely copied, but there is a function that you may use (explicitely) if you really need to spend time for a copy.

I know it's strange and annoying, but this is how it works.

It doesn't sound strange to me; this is exactly what I need as a "general-purpose programmer". Pointer manipulation is one of the most powerful features of this kind of languages. :D

Lua is similar to C/C++ in matrix handling; this means that it has very poor matrix support.

That's correct... C++ just don't care about matrices. I never need matrix manipulation in my C++ programs, because those are features designed for math programs, and I don't write any math programs myself (like 90% of the other C++ programmers). However, if I somehow need such a feature for my program, I just have to write or import a library to add matrix support, and everything will be fine. :)

(unless you want to create a pointer -- but usually you don't want such a thing)

I do! :D And I'm not the only one ;)

Btw, AFX_Master, you should add such an explanation to your CPLua tutorial.

I agree. People should know what they are exactly doing when manipulating Lua tables ;)

#14 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 13 September 2006 - 06:42 PM

the thing that annoyed me the most in LUA is the fact that tables are counted from 1... Argh, and also the fact that the "continue" statement doesn't exist !

If only there was something like PHP available for general purpose scripting even without all its builtin libraries PHP is better than LUA is my opinion...

#15 girdeux

girdeux

    Casio Addict

  • Members
  • PipPipPip
  • 88 posts
  • Location:Spain / Castell?n

  • Calculators:
    casio fx-115ms;
    casio classpad 300

Posted 13 September 2006 - 06:46 PM

Ok I think that I have caugth the idea. In Lua, if a and b are tables, when you put a=b it implies b=a & a=b; but if a & b are numbers, a=b doesn't imply b=a. That's it? :)

Well I'm reading programming whit Lua (it's very very long) when I have time the reading goes on. I will make my questions about that here, (I will think in my doubt before post my question), in this wey you can know the doubs of novices of Lua. If someone answer my questions I will thank for it.

I have a litle question: I understand the function braek, but function return seems to be equal, what is the differences between them??. :huh:

#16 Orwell

Orwell

    Casio Overlord

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

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 13 September 2006 - 07:20 PM

and also the fact that the "continue" statement doesn't exist !

There is a "powerpatch" to add the "continue" statement in Lua. If several people are interested I can try to apply it on CPLua :)
Btw there is also a patch to optimize the use of integer numbers (with this you don't have to use floating point numbers to store integer values). I'll make a few tests later to see if it would be interesting for CPLua.

Ok I think that I have caugth the idea. In Lua, if a and b are tables, when you put a=b it implies b=a & a=b; but if a & b are numbers, a=b doesn't imply b=a. That's it? :)

If "a" is a table, you should actually think that "a" is only a variable which holds the adress of the real table. Then if you write "b=a", you only copy the table's adress into b, not the table itself. Thus "a" and "b" refer to the same adress and thus to the same table. It's the same thing for functions and userdata's. ;)

I have a litle question: I understand the function braek, but function return seems to be equal, what is the differences between them??.

"break" is useful to break a loop, while "return" breaks a function.
For example:
function example()  -- wait for the user to press left or right arrow
  while 1 do
	if testkey(K_RIGHT) then break end  -- break the "while" loop when right arrow is pressed
	else if testkey(K_LEFT) then return "left" end  -- return from the function 
  end
  return "right"
end
PS: Note that this example is very bad programmed.
A better code would be
function example()  -- wait for the user to press left or right arrow
  local le, ri = false, false
  repeat
	le = testkey(K_LEFT)
	ri = testkey(K_RIGHT)
  until le==true or ri==true
  if le==true then return "left" else return "right" end
end
;)

#17 The_AFX_Master

The_AFX_Master

    Casio Overlord

  • Admin
  • PipPipPipPipPipPipPip
  • 519 posts
  • Gender:Male
  • Location:Black Mesa Research Facility (sector C)
  • Interests:BASIC +FORTRAN 90+ C++.....and HALF LIFE

  • Calculators:
    Casio Algebra FX 2.0 Plus, Casio fx 570 ms, Classpad 300, And a crowbar

Posted 13 September 2006 - 07:26 PM

Btw, AFX_Master, you should add such an explanation to your CPLua tutorial.


Sure, i'm in tables now, i will post in a few minutes. As far i know, if you need to copy a table, you need to use table.copy(), or do a loop over the table (agh!... so boring! :wacko: ).

#18 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 14 September 2006 - 08:50 AM

Create implicit copies of matrices would require a lot of time and memory, and most programmers won't need this feature and won't accept to lose time and memory for that

This argument has been used by all C/C++ programmers worldwide, again and again... I know why; because it's the only argument they can use. Their conclusion is always the same: "I don't need matrices, they don't really exist in C, and I am happy with that; but even if I need them, I can use a matrix library". I totally disagree. What do you mean with "most" programmers? I can reply that most programmers in scientific programming use matrices all the time, because every aspect of Physics or Mathematics is full of matrices.

It doesn't sound strange to me; this is exactly what I need as a "general-purpose programmer". Pointer manipulation is one of the most powerful features of this kind of languages. :D
That's correct... C++ just don't care about matrices. I never need matrix manipulation in my C++ programs, because those are features designed for math programs, and I don't write any math programs myself (like 90% of the other C++ programmers). However, if I somehow need such a feature for my program, I just have to write or import a library to add matrix support, and everything will be fine. :)

I never (or almost never) use pointers, but I always use matrices.
Ok, it seems that we are starting a debate concerning which programming language is better. We have done such a debate in the past, and it's totally meaningless to start again. I hope that we can at least agree with that: scientific programming can be done in C++, but nobody wants to do that, because Fortran 95 is much better for Mathematics. On the other hand, nobody wants to write an operating system in Fortran; it can be done, but C++ can do it much better.

#19 Orwell

Orwell

    Casio Overlord

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

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 14 September 2006 - 09:25 AM

scientific programming can be done in C++, but nobody wants to do that, because Fortran 95 is much better for Mathematics. On the other hand, nobody wants to write an operating system in Fortran; it can be done, but C++ can do it much better.

Remember the example I gave earlier: You can have a nice, superfast car, but you will never want to cross the oceans with it :lol: Programming languages are designed for specific purposes, and they are optimized with consideration for these purposes. :)

#20 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 14 September 2006 - 10:00 AM

Remember the example I gave earlier: You can have a nice, superfast car, but you will never want to cross the oceans with it :lol: Programming languages are designed for specific purposes, and they are optimized with consideration for these purposes. :)

Remember the example I gave several months ago: Developing mathematical programs in C++ instead of Fortran 95 is like this: you have a Fiat Panda and a Lamborghini Countach, you want to go from Paris to, say, Moscow, and you take Fiat Panda instead of Lamborghini :plol:.

#21 Orwell

Orwell

    Casio Overlord

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

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 14 September 2006 - 10:16 AM

Remember the example I gave several months ago: Developing mathematical programs in C++ instead of Fortran 95 is like this: you have a Fiat Panda and a Lamborghini Countach, you want to go from Paris to, say, Moscow, and you take Fiat Panda instead of Lamborghini :plol:.

:plol: This comparison is good for CPBasic and CPLua, because these are languages with the same purposes but with big differences in performance.

Suppose Fortran is a car and C++ is a boat :P
You can ride from Paris to Moscow with your car, and I can sail from France to USA with my boat.
I can go to Moscow if I want, I just have to add wheels to my boat. But of course I won't be as fast as your car. And you could go from France to USA too, if you add some floats to your car. But I bet you won't be as fast as my boat :lol: I think this clearly illustrates the debate :rolleyes:

#22 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 14 September 2006 - 10:24 AM

:plol: This comparison is good for CPBasic and CPLua, because these are languages with the same purposes but with big differences in performance.

Indeed :rolleyes:.

Suppose Fortran is a car and C++ is a boat :P
You can ride from Paris to Moscow with your car, and I can sail from France to USA with my boat.
I can go to Moscow if I want, I just have to add wheels to my boat. But of course I won't be as fast as your car. And you could go from France to USA too, if you add some floats to your car. But I bet you won't be as fast as my boat :lol: I think this clearly illustrates the debate :rolleyes:

Excellent! I totally agree. :lol2:

#23 Orwell

Orwell

    Casio Overlord

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

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 14 September 2006 - 10:46 AM

I think this could make a good french proverb:

Une bonne voiture roule toujours plus vite qu'un bon bateau avec des roues

:greengrin:

#24 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 14 September 2006 - 01:20 PM

yes that's a goog proverb, maybe a real one exists with the same meaning :)

#25 girdeux

girdeux

    Casio Addict

  • Members
  • PipPipPip
  • 88 posts
  • Location:Spain / Castell?n

  • Calculators:
    casio fx-115ms;
    casio classpad 300

Posted 17 September 2006 - 03:53 PM

For example I create one function, and save it in the folder: main/name; then I want to use this function in other file, I write on the top: require ("main/name"), but the function doesn't work, why?

Other thing: I create a simple pictur like this:

require ("draw")
pic = pict.new(5,5)
draw.onscreen()

But nothing apears.. how can I see this pictur in the screen? :blink:

#26 Orwell

Orwell

    Casio Overlord

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

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 17 September 2006 - 05:44 PM

For example I create one function, and save it in the folder: main/name; then I want to use this function in other file, I write on the top: require ("main/name"), but the function doesn't work, why?

If you want to use your function in another file than main/name, you must export it explicitely at the end of main/name.

For example:
-- FILE "main/name"

function example()
  print("hello!")
end

export{example=example}  -- exports "example"


-- other file:
require("main/name")  -- imports "example" from main/name
example()

Other thing: I create a simple pictur like this:

require ("draw")
pic = pict.new(5,5)
draw.onscreen()

But nothing apears.. how can I see this pictur in the screen? :blink:

pic = pict.new(5,5) is just creating a new picture called "pic". This picture is not drawed at that time. With draw.onscreen() you just indicated that drawing operations must be sent to the screen. But you must use draw.pict() too to make the picture appear ;)
Note that a new picture is white by default, thus you wouldn't see it on a white screen.
An example is
require ("draw")
pic = pict.new(5,5)
draw.onpict(pic) -- draw on the picture
draw.rect(0,0,4,4)
draw.onscreen() -- now draw on the screen
draw.pict(10,10,pic) -- make the pict appear


#27 girdeux

girdeux

    Casio Addict

  • Members
  • PipPipPip
  • 88 posts
  • Location:Spain / Castell?n

  • Calculators:
    casio fx-115ms;
    casio classpad 300

Posted 18 September 2006 - 01:56 PM

Ok the function in other file works perfect with export. Sorry, but I write this code, and nothing apears, only Done.

require ("draw")
pic = pict.new(5,5)
draw.onpict(pic) -- draw on the picture
draw.rect(0,0,4,4)
draw.onscreen() -- now draw on the screen
draw.pict(10,10,pic) -- make the pict appear



#28 Orwell

Orwell

    Casio Overlord

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

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 18 September 2006 - 02:52 PM

Ok the function in other file works perfect with export. Sorry, but I write this code, and nothing apears, only Done.

Then add this at the end:
showgraph()  -- show the graph window
waitinput()  -- wait for a key

Btw, reading the examples could be instructive <_<

#29 girdeux

girdeux

    Casio Addict

  • Members
  • PipPipPip
  • 88 posts
  • Location:Spain / Castell?n

  • Calculators:
    casio fx-115ms;
    casio classpad 300

Posted 02 October 2006 - 09:36 PM

One problem whit LUA, in this code:

require('LNA/TrapAd')
function f(x) return math.exp(3*x) end
q=TrapAdapt(f,0,3)
print(q)

My class pad 300 doesn't respond, (it's many time thinking and nothing is shown)* I think it's wouldn't have to be difficult for LUA, if I use Romberg instead TrapAdapt happens the same.
Can it be the memory?? what can I do? I have 415108 free bytes, I think it is sufficient.

*In spanish: que se me cuelga :banghead:

#30 The_AFX_Master

The_AFX_Master

    Casio Overlord

  • Admin
  • PipPipPipPipPipPipPip
  • 519 posts
  • Gender:Male
  • Location:Black Mesa Research Facility (sector C)
  • Interests:BASIC +FORTRAN 90+ C++.....and HALF LIFE

  • Calculators:
    Casio Algebra FX 2.0 Plus, Casio fx 570 ms, Classpad 300, And a crowbar

Posted 02 October 2006 - 10:47 PM

Can it be the memory?? what can I do? I have 415108 free bytes, I think it is sufficient.

*In spanish: que se me cuelga :banghead:

As far i know, the Storage RAM (415108 bytes free) is totally independant from calculation RAM (1.2 mb in O.S 2.2). when the memory fills up, you see an "Alloc Failed" message, sure, isn't memory problem

Could be:

-waitkey(), waitpen(), waitinput() functions running (check it if your code is bigger than the sample that you posted)
-Your'e on graph window, you can activate the console on the code with showconsole()
but the probability of the last issues that i mentioned is a silly 1% :( . And sure isn't a time consuming operation (the CP CAS give the result in a blink :blink: ).

Wait for PAP, he's the owner of PAP MICROSYSTEMS, and he could help you.

PD: Hey PAP, what about state PAP MICROSYSTEMS :D , joke :lol2:

#31 girdeux

girdeux

    Casio Addict

  • Members
  • PipPipPip
  • 88 posts
  • Location:Spain / Castell?n

  • Calculators:
    casio fx-115ms;
    casio classpad 300

Posted 03 October 2006 - 05:39 PM

Ok I wait more time and the class pad takes 2 min, more or less, to do Romberg(f,0,3); f=e^(3x). Is it normal?? :huh: It is faster if I change function, for example: f=1/((1-x)*(0.05+0.5*x))

If I undestand Storage RAM doesn't affect to calculation speed, but calculation RAM yes, and is 1,2 mb in OS 2.2. This calculation RAM is always 1,2?? There are any form to increase this calculation RAM??

Other question: there are any form to delate geometry, conical, sequences, presentation aplications?? I don't use them.

#32 Orwell

Orwell

    Casio Overlord

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

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 03 October 2006 - 08:15 PM

If I undestand Storage RAM doesn't affect to calculation speed, but calculation RAM yes

:huh: Of course not: does the free space on your hard disk help your processor to run faster? These are completely different things...
Execution speed has nothing to do with the size of free memory space (RAM or Storage).

and is 1,2 mb in OS 2.2. This calculation RAM is always 1,2?? There are any form to increase this calculation RAM??

Hey, it was 180 Kb in CPLua 0.9B, it's now 1.2 Mb in the current version, and you still want more? :blink:

#33 girdeux

girdeux

    Casio Addict

  • Members
  • PipPipPip
  • 88 posts
  • Location:Spain / Castell?n

  • Calculators:
    casio fx-115ms;
    casio classpad 300

Posted 03 October 2006 - 10:32 PM

Hey, it was 180 Kb in CPLua 0.9B, it's now 1.2 Mb in the current version, and you still want more? :blink:


Ok Ok I compared it with my PC RAM (512 Mb), but I suppose that CP isn't a PC, I believe you. :P

When we can get CPLua 0.9? And LUA 1.7? Or it's now available and I had not found out? (I only ask, you can get your time) :rolleyes:

#34 girdeux

girdeux

    Casio Addict

  • Members
  • PipPipPip
  • 88 posts
  • Location:Spain / Castell?n

  • Calculators:
    casio fx-115ms;
    casio classpad 300

Posted 04 October 2006 - 07:01 PM

p=0.3-0.4
h=1.2-1.3
print(p==h)  --> false ??????????  :banghead: 

p=0.7-0.8
print(p==h) --> true ok

Is my CP?? What happens?? :cry: p=-0.1, h=-0.1 print(-0.1==-0.1) --> no ??

#35 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 04 October 2006 - 08:18 PM

When we can get CPLua 0.9? And LUA 1.7? Or it's now available and I had not found out? (I only ask, you can get your time) :rolleyes:

According to the developer (Orwell), CPLua is in version 0.9D. If I understand well, this is a pre-pre release candidate.
The only person who has LNA version 1.70 is me ;), because I haven't released it yet. I'm still trying to find the time needed to update the documentation, hence the delay...

#36 girdeux

girdeux

    Casio Addict

  • Members
  • PipPipPip
  • 88 posts
  • Location:Spain / Castell?n

  • Calculators:
    casio fx-115ms;
    casio classpad 300

Posted 05 October 2006 - 10:19 PM

p=0.3-0.4
h=1.2-1.3
print(p==h)  --> false ??????????

Please can someone help me with this??, p and h are equal to -0.1, and my CP says that they are different. It's only my CP?? What's happens?? :banghead:

And what's about my question: it's normal that my CP takes 2 min to do Romberg(f,0,3); f=math.exp(3x)??

#37 Orwell

Orwell

    Casio Overlord

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

  • Calculators:
    Casio AFX 1.02 / Casio ClassPad 300

Posted 06 October 2006 - 08:49 AM

Actually this question already appeared several times... but well <_<

First of all, your CP isn't different from the other ones. If you get some strange results, then most people should have the same thing.

And second, this is not a bug... It's the correct result :/
CPLua uses floating point numbers as basis type for numbers, that means that it only uses some good approximations of the exact numbers.
For example, "0.3" for you might be "0.299999999999" for CPLua.

If you do "print(0.3-0.4)", you will see -0.1, but the exact result was perhaps -0.10000001. CPLua rounds the number to -0.1 for lisibility.
But if you do "print(1.2-1.3)", you will also see -0.1, but perhaps the exact result was -0.99999999.
Then if you compare the 2 results, CPLua will tell you that these numbers are not equal. And this is correct <_<

I know it is very disturbing. Unfortunately I can't correct this effect :(
Everytime you use decimal numbers, you must think that the equality operator "==" could return some unexpected results. If you really want to compare two real numbers A and B, you should write something like "abs( A-B )<eps" where "eps" is a really small number.

It sounds weird I know, but this is how computers work (not only the CP) ;)
Then why isn't there any error if you try the same thing in the Main Application? (or even with the CAS package; try this:
require("cas")
A = cas("0.3")
B = cas("1.2")
print( (A-0.4)==(B-1.3) )
)
Simply because the CP uses BCD numbers for the CAS instead of floating points numbers (for better precision). Unfortunately, it is a lot slower :banghead:


PS: actually I have a suggestion about this, but I'll post it in the "Suggestions" topic later :)

#38 girdeux

girdeux

    Casio Addict

  • Members
  • PipPipPip
  • 88 posts
  • Location:Spain / Castell?n

  • Calculators:
    casio fx-115ms;
    casio classpad 300

Posted 06 October 2006 - 03:35 PM

Thank you :D

#39 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 2006 - 10:06 PM

One problem whit LUA, in this code:

require('LNA/TrapAd')
function f(x) return math.exp(3*x) end
q=TrapAdapt(f,0,3)
print(q)
My class pad 300 doesn't respond, (it's many time thinking and nothing is shown)* I think it's wouldn't have to be difficult for LUA, if I use Romberg instead TrapAdapt happens the same.
Can it be the memory?? what can I do? I have 415108 free bytes, I think it is sufficient.

(Sorry for answering late, but I didn't noticed your post before)
Well, there is no problem here: TrapAdapt tries to compute your integral with the default accuracy, which is 1E-6. In this case, this accuracy is very large, since the correct result is (exp(9)-1)/3=2700.69, which is huge, compared to 1E-6. You can obtain a very accurate result by reducing accuracy, using the optional argument eps. For example, setting eps=0.01 gives 2700.70 in about one second. Note that the result has an error equal to 0.01, as requested.
Btw, memory is not a problem here, no matter what accuracy you choose.

Ok I wait more time and the class pad takes 2 min, more or less, to do Romberg(f,0,3); f=e^(3x). Is it normal?? :huh: It is faster if I change function, for example: f=1/((1-x)*(0.05+0.5*x))

Yes, it is normal, for the same reason. Note that Romberg is in general faster and more accurate than TrapAdapt, but not always (read the manual for details). Set eps=0.01 to get a very accurate result easily.
In general, if an LNA computation needs a lot of time, reduce accuracy, then increase it slightly, and compare the results given.
Prease remember that Numerical Analysis is an art, but it's not magic. There is no computer system which is able to solve any problem numerically with great accuracy and in no time.

--> PS: I think that you should post those questions to the LNA topic. LNA is a library written in CPLua; it's not part of the Lua language.

Wait for PAP, he's the owner of PAP MICROSYSTEMS, and he could help you.
PD: Hey PAP, what about state PAP MICROSYSTEMS :D , joke :lol2:

I like your sense of humor, although "MicroSystems" reminds me Micro..ft, which is disgusting.

#40 girdeux

girdeux

    Casio Addict

  • Members
  • PipPipPip
  • 88 posts
  • Location:Spain / Castell?n

  • Calculators:
    casio fx-115ms;
    casio classpad 300

Posted 07 October 2006 - 01:13 PM

Thank you PAP, you make a good job with LNA.

I solved my floating point numbers and Romberg problems. :D

--> PS: I think that you should post those questions to the LNA topic. LNA is a library written in CPLua; it's not part of the Lua language.


Ok I post my LNA doubts in Cplua Project: Luanuman.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users