I Love it .

**we are waiting for the CAS**

If CpLua support the CAS ,

I think a big project can be

**Partial Differential Equations**!

what is your Idea about this project ?

Started by
Orwell
, Sep 01 2005 04:23 PM

858 replies to this topic

Posted 08 September 2005 - 10:25 PM

I wrote the secant program for finding roots of a function , Lua is really fast !!!

I Love it .

**we are waiting for the CAS**

If CpLua support the CAS ,

I think a big project can be**Partial Differential Equations **!

what is your Idea about this project ?

I Love it .

If CpLua support the CAS ,

I think a big project can be

what is your Idea about this project ?

Posted 08 September 2005 - 10:27 PM

not yet, but I will certainly add some very soonIs there any Input statments ? like :

Input

Input Functions

,...

Hmm this isn't so goodplease explain about the

math.radfunction

try this code :

u=math.rad(180)

print(math.sin(u))

the math.rad() function from degrees to radians.

Thus math.rad(180) gives the PI number as result, but since the interpreter use double as type when manipulating numbers the precision is not perfect, and sin(u) returns 1.22e-16 and not exactly zero.

This is a common problem... If you really need it I could try to use the native BCD type of the classpad to ensure perfect precision, but i'm afraid it will slow down the execution

Posted 08 September 2005 - 10:29 PM

For now I will just try to wrap the SDK CAS function to the Lua language.I wrote the secant program for finding roots of a function , Lua is really fast !!!

I Love it .we are waiting for the CAS

If CpLua support the CAS ,

I think a big project can bePartial Differential Equations!

what is your Idea about this project ?

I don't really know if it is possible to implement that, but we can still give it a try

Posted 08 September 2005 - 10:47 PM

Works as expected (except the "OVR" button, but we already know this).New keyboard, new version!

v. 0.51 is available

The only thing that is missing is a key for "cutting" text. Since "cutting" is a very common operation, I think that it should be added somewhere. Maybe the "Copy" button should become "Cut" in shift mode...

Posted 08 September 2005 - 10:56 PM

You are right... But pressing shift+copy is the same as pressing copy+backspace isn't itWorks as expected (except the "OVR" button, but we already know this).

The only thing that is missing is a key for "cutting" text. Since "cutting" is a very common operation, I think that it should be added somewhere. Maybe the "Copy" button should become "Cut" in shift mode...

Posted 08 September 2005 - 11:06 PM

I recently started to write some real functions in Lua, directly on my calculator (naturally, I'm currently the only one here who can make tests with CPLua on his computer, and it's pretty handy ) .

I discovered that it can get really difficult to read when the small font is used, especially with ponctuation like dots, commas etc. I think I could adjust some characters of the font, for example make bigger dots (2x2 and not 1x1) etc. What do you think? Since you used it more than me I would like to have your point of view...

Btw, I think I will now release the CPLua executables with the add-in "beta" versions, so anyone else could make tests on his computer which is though a little bit faster (It won't give a correct idea of the add-in's speed however)

I discovered that it can get really difficult to read when the small font is used, especially with ponctuation like dots, commas etc. I think I could adjust some characters of the font, for example make bigger dots (2x2 and not 1x1) etc. What do you think? Since you used it more than me I would like to have your point of view...

Btw, I think I will now release the CPLua executables with the add-in "beta" versions, so anyone else could make tests on his computer which is though a little bit faster (It won't give a correct idea of the add-in's speed however)

Posted 08 September 2005 - 11:47 PM

I do want to start such a topic as soon as possible, but I want to finish (and check) the second "heavy" test of CPLua first (see previous posts). This project is rather large, and several numerical methods are needed as sub-projects. One of them is Romberg integration. I'm currenlty working on this, and it's almost completed.

please start the topic!

Actually, it's easy to write all the code needed, since I already have written such algoritms in Fortran 95, but I want a neat, structured and robust Lua code, and this needs extensive testing. I hope that the project will be finished and checked in a few days. However, I just realized that, in order to write a short (but still structured) code, a "Lua library" containing common arithmetic operations should be very useful. For example, functions such as "sign", "masked sum", "merge" etc, are available in Fortran 95, but not in Lua; I'm planning to add such functions in a library, since they are very useful, and there is no need to rewrite them in every project that needs them. This, however, will slow down the project a bit. Since I have many other things to do (as everybody), I will need some time, but not much. This project will make ClassPad able to find

Yes! We really do!we are waiting for the CAS

Actually, the CAS is not needed for solving partial differential equations (PDEs) numerically, except if you meanIf CpLua support the CAS ,

I think a big project can be Partial Differential Equations !

what is your Idea about this project ?

This is perharps the first CAS-related thing that should be implemented...Is there any Input statments ? like :

Input Functions

Posted 08 September 2005 - 11:56 PM

During writing an new program, I use the normal font which is easier to read. I use the small font only for inspecting the code, during debbugging, checking etc, since you can see more text in one screen. The small font looks ok to me for that purpose. I don't think that adjusting some characters will improve visibility significantly.I discovered that it can get really difficult to read when the small font is used, especially with ponctuation like dots, commas etc. I think I could adjust some characters of the font, for example make bigger dots (2x2 and not 1x1) etc. What do you think? Since you used it more than me I would like to have your point of view...

Posted 09 September 2005 - 02:28 AM

Hi guys.

This is my first reply in a while, i have a lot of work, need a new job (of course in another city, i must move), i have problems with my PC... So i have a bit of free time. This seems very interesting, let me have more free time and i will read the documentation, and if i have enough time, i will try to translate it to spanish.

This is my first reply in a while, i have a lot of work, need a new job (of course in another city, i must move), i have problems with my PC... So i have a bit of free time. This seems very interesting, let me have more free time and i will read the documentation, and if i have enough time, i will try to translate it to spanish.

Posted 09 September 2005 - 08:04 AM

Tell me all the arithmetic operations you want and I will add it to the 'math' library (which is in C thus faster)However, I just realized that, in order to write a short (but still structured) code, a "Lua library" containing common arithmetic operations should be very useful. For example, functions such as "sign", "masked sum", "merge" etc, are available in Fortran 95, but not in Lua; I'm planning to add such functions in a library, since they are very useful, and there is no need to rewrite them in every project that needs them.

Note that I'm not sure to know all of them, so please remember me how they work (I know what "sign" does naturally, but I never used features like "masked sum" etc )

Indeed, I was already thinking about this.This is perharps the first CAS-related thing that should be implemented...

But entering a function is not quite different from entering a simple string (since CAS can translate expressions from strings), so I think it should be ok

Posted 09 September 2005 - 10:32 AM

I want to finish (and check) the second "heavy" test of CPLua first (see previous posts). This project is rather large, and several numerical methods are needed as sub-projects. One of them is

Romberg integration. I'm currenlty working on this, and it's almost completed.

I completed Romberg Integration

one Example :

Int(math.log10(math.sqrt(x^5)),x,1,2)

the result is : 0.41941377356149

It takes

(It has just one output )(t32(5)=0.41941377356149

please give an Example with the time it takes to test it.thanks.

--------------

( edited post )

Posted 09 September 2005 - 10:37 AM

Wow. Is this the correct result?Int(math.log10(math.sqrt(x^5)),x,1,2)

Because 'math.log10(math.sqrt(x^5))' is supposed to be a number, not a fonction... Or did I miss something?

Posted 09 September 2005 - 12:06 PM

I think a more appropriate syntax should be

-- your own function to study a "f(x)"-like function (here it just computes a sum) function Sum(func, first, last) local sum=0 for i=first, last do sum = sum + func(i) end return sum end -- the function to study function F(x) return math.log10(math.sqrt(x^5)) end -- call of your function s = Sum( F, 1, 2)I think this should work

Posted 09 September 2005 - 12:09 PM

Wow. Is this the correct result?

Because 'math.log10(math.sqrt(x^5))' is supposed to be a number, not a fonction... Or did I miss something?

the rumberg Rule perform the Integral with numerical methods .

you are right , Int(f(x),x,a,b ) is not a function just screen output !!!

Posted 09 September 2005 - 01:01 PM

Actually, I was thinking of a more robust program, which uses Romberg integration rule iteratively, until a predescribed accuracy is reached. It can be done easily, but it is somewhat more complex to make it work without unecessary operations in each iteration. I hope that I will finish it today, and, of course, I'll let you know.I completed Romberg Integration

one Example :

Int(math.log10(math.sqrt(x^5)),x,1,2)with N=32(it is just screen output not a function)

the result is : 0.41941377356149

It takesless than 1 seconds, How about your algorithm ?

(It has just one output )(t32(5)=0.41941377356149

please give an Example with the time it takes to test it.thanks.

Posted 09 September 2005 - 02:15 PM

Here are the results of my last test

Posted 09 September 2005 - 03:11 PM

Wow, this way we can extend Lua itself! However, Fortran 95 has a lot of numerical functions, and their implementation in C is not an easy task. Here is why:Tell me all the arithmetic operations you want and I will add it to the 'math' library (which is in C thus faster) :)

Note that I'm not sure to know all of them, so please remember me how they work (I know what "sign" does naturally, but I never used features like "masked sum" etc :rolleyes:)

(1) Many Fortran 95 functions take as arguments matrices with arbitrary dimensions. Unfortunately, matrix support in C is not its strong point. Furthermore, there are

(2) Fortran 95 makes extensive use of "named" optional arguments. This permits to call the function with all optional arguments omitted, except the arguments you want. I've already used optional arguments in Lua using the arg function, but they are not named. For example, let's assume that the function foo takes a mandatory argument a, and two optional arguments b and c. In Fortran 95, you can call the function as foo(a,c=5), which means that only the second optional argument (c) is used, while the first (b) is omitted. There is certainly a way to implement this in C, but it will not be as easy as in Fortran.

(3) Most Fortran 95 functions are "elemental", that is, they can operate on a scalar or on a matrix with arbitrary dimensions. In the latter case they operate on each element of the matrix iteratively.

Although implementing all this stuff in C is a hard work, I think that we can at least add the most useful functions. Here is a small list of very useful functions. I've added several representative examples:

sign(a,b): Returns the absolute value of a, set to the same sign as b. Examples:

sign(2,-3) ---> -2

sign(-2,3) ---> 2

sign(-2,-3) ---> -2

sign(0,-3) ---> 0

sign(0,3) ---> 0

This is actually an extension of the sign function, as is defined in other languages.

sum(array,dim,mask): Adds the elements of array along dimension dim, provided that they satisfy the condition mask. The arguments dim and mask are optional. If dim is omitted, all elements will be added, provided that they satisfy the mask. If mask is omitted, all elements will be added. Examples: if A={{1,2,3},{4,5,6}} then:

sum(A) ---> 21

sum(A,dim=1) ---> sums across columns; yelds {5,7,9}

sum(A,dim=2) ---> sums across rows; yelds {6,15}

sum(A,mask=A>=5) --> 11

sum(A,dim=1,mask=A>=5): sums across columns; only elements equal or larger than 5 are taken into account; yields {0,5,6}

sum(A,dim=2,mask=A>=5): sums across rows; only elements equal or larger than 5 are taken into account; yields {0,11}

maxval(array,dim,mask):: returns the maximum value of the elements of array along the dimension dim, provided that they satisfy the mask. Examples:

maxval(A) ---> 6

maxval(A,dim=1) ---> maximum values in each column; yields {4,5,6}

maxval(A,dim=2) ---> maximum values in each row; yields {3,6}

maxval(A,mask=A<4.5) ---> 4

maxval(A,dim=1,mask=A<4.5) ---> maximum values in each column; only elements less than 4.5 are taken into account; yields {4,2,3}

maxval(A,dim=2,mask=A<3.5) ---> maximum values in each row; only elements less than 3.5 are taken into account; yields {3,nil}

maxloc(array,mask): Returns an integer vector, giving the position (dimension subscripts) of the largest element of array that satisfies the mask. If there are more than one maximum elements, the first one is returned. If no elemnt satisfies the mask, a zero vector is returned. Examples:

maxloc(A) ---> {2,3} (the maximum value is at 2nd row, 3rd column)

maxloc(A,mask=A<4.5) ---> {2,1} (the maximum value less than 4.5 is at 2nd row, 1st column)

maxloc(A,mask=A<0) ---> {0,0} (there are no elements less than 0)

minval(array,mask):: As maxval, but returns the minimum value. Examples:

minval(A) ---> 1

minval(A,dim=1) ---> minimum values in each column; yields {1,2,3}

minval(A,dim=2) ---> minimum values in each row; yields {1,4}

minval(A,mask=A>4.5) ---> 5

minval(A,dim=1,mask=A>4.5) ---> minimum values in each column; only elements greater than 4.5 are taken into account; yields {nil,5,6}

minval(A,dim=2,mask=A<3.5) ---> minimum values in each row; only elements greater than 3.5 are taken into account; yields {1,nil}

minloc(array,mask):: As maxloc, but returns the position of the minimum. Examples:

minloc(A) ---> {1,1} (the minium value is at 1st row, 1st column)

minloc(A,mask=A>4.5) ---> {2,2} (the maximum value greater than 4.5 is at 2nd row, 2nd column)

minloc(A,mask=A<0) ---> {0,0} (there are no elements less than 0)

That's all... for now. If you decide to add these functions in the math library, let us know. We will certainly use them...

Posted 09 September 2005 - 03:31 PM

change the f(x) function and test the result !

I think

you can change the function for any value of N .

the calculators do not perform the Integration(the numerical) for any value of N,

I do not mean that it is impossible , I think it is not really needed !

--------------------------------------------------------------------------

about the function :

a , b are the interval limits (a,b )

N is the accurancy , the values available for N are: 2,4,8,16,32

-----------------------------the function-------------------------------

function rumberg(a,b,N) -----------change this function to your desired one---------------- function f(x) return math.log10(math.sqrt(x^5)) end -----------this function return {2,4,8,16,32} ( the N values)------- function m(x) return ((x^5/120)-(x^4/12)+(11*x^3)/24-(11*x^2)/12+(23*x/15)) end -----------this function controls the for loop ------------------------- function n(x) return ((x^5/31744)-(31*x^4/15360)+(155*x^3/3584)-(155*x^2/384)+(31*x/16)-(624/1085)) end h1=(b-a)/1 d10=h1/2*(f(a)+f(a+h1)) q=n(N) if q<2.5 and q>1.5 then h=2 end if q<3.5 and q>2.5 then h=3 end if q<4.5 and q>3.5 then h=4 end if q<5.5 and q>4.5 then h=5 end if q<6.5 and q>5.5 then h=6 end if q>6 then h=n(N) end for j=2,h do d=m(j) if d<2.5 and d>1.5 then i=2 end if d<4.5 and d>3.5 then i=4 end if d<8.5 and d>7.5 then i=8 end if d<16.5 and d>15.5 then i=16 end if d<32.5 and d>31.5 then i=32 end if i==2 then h2=(b-a)/2 sum=0 for k=1,(i-1) do sum=sum+f(a+k*h/2) end d20=h2/2*(f(a)+2*sum+f(a+2*h2)) d21=(4*d20-d10)/3 end if i==4 then h4=(b-a)/4 sum=0 for k=1,(i-1) do sum=sum+f(a+k*h4) end d40=h4/2*(f(a)+2*sum+f(a+4*h4)) d41=(4*d40-d20)/3 d42=(4^2*d41-d21)/(4^2-1) end if i==8 then h8=(b-a)/8 sum=0 for k=1,(i-1) do sum=sum+f(a+k*h8) end d80=h8/2*(f(a)+2*sum+f(a+8*h8)) d81=(4*d80-d40)/3 d82=(4^2*d81-d41)/(4^2-1) d83=(4^3*d32-d42)/(4^3-1) end if i==16 then h16=(b-a)/16 sum=0 for k=1,(i-1) do sum=sum+f(a+k*h16) end d160=h16/2*(f(a)+2*sum+f(a+16*h16)) d161=(4*d160-d80)/3 d162=(4^2*d161-d81)/(4^2-1) d163=(4^3*d162-d82)/(4^3-1) d164=(4^4*d163-d83)/(4^4-1) end if i==32 then h32=(b-a)/32 sum=0 for k=1,(i-1) do sum=sum+f(a+k*h32) end d320=h32/2*(f(a)+2*sum+f(a+32*h32)) d321=(4*d320-d160)/3 d322=(4^2*d321-d161)/(4^2-1) d323=(4^3*d322-d162)/(4^3-1) d324=(4^4*d323-d163)/(4^4-1) d325=(4^5*d324-d164)/(4^5-1) end end if N==2 then return print("I="..d21) end if N==4 then return print("I="..d42) end if N==8 then return print("I="..d83) end if N==16 then return print("I="..d164) end if N==32 then return print("I="..d325) end end ----------------------------End -----------------------------------

Posted 09 September 2005 - 03:33 PM

Looks quite promising. Indefinite integration in Lua, using the CAS! Can you give us an example of definite integration, with or without using the tolerance argument? That is, is it possible to use the CAS commands:Here are the results of my last test

integral(x^2+y^3,y,0,1) (result: x^2+1/4)

and

integral(1/sqrt(arctan(x)),x,0,1,1e-5) (result: 2.057117417)

???

What exactly does the cas function? Can it be used to call any CAS function or command?

Posted 09 September 2005 - 03:34 PM

Wow, I've many things to say. I'm writing, don't move

Posted 09 September 2005 - 03:48 PM

I'm afraid I don't agree. Romberg integration is accurate, but using a fixed nuber of N is definitely not the best choice. You cannot get a very accurate result this way, unless you integrate simple functions.I think

with N=32we have the must accurate result ,

Who said that? It's not true.the calculators do not perform the Integration(the numerical) for any value of N,

ItI do not mean that it is impossible , I think it is not really needed !

No offense, of course, but your code is not structured at all, and it does not make use of the powerful capabilities of Lua. You will have problems on understanding what this code does very soon. Furthermore, the accuracy of the algorithm is not controlled, and it is not easy to add new capabilities in the future. It works, but it is not general, and has limited use. Good start, anyway...

Posted 09 September 2005 - 03:56 PM

Actually that's what I do from the beginning, by adapting some existing functions (like print etc) or by creating new ones (like testkey etc) I have complete control on the Lua "libraries", however I can't change anything to the language itselfs, or to the syntax.Wow, this way we can extend Lua itself!

Thanks for your many examples. Implementing the sign() functions is easy, I will do it immediatly (there will be a math.sign() function which takes one or 2 arguments). Concerning the other functions they seem to principaly do manipulations on arrays, and there are indeed no appropriate functions for it. Maybe I will create a "array" library with this kind of functions, like the existing "table" library (which can be used for tables manipulation). However I won't be able to implement the "named" optional arguments, since it is a limitation of the Lua language itselfs.

I didn't find the correct way to do it with the CAS yet, but it is certainly possible. I will ask SoftCalc about itCan you give us an example of definite integration, with or without using the tolerance argument?

It is not a function, it is a table that contains (or will contain) all CAS related functions. It has the same purpose as the 'math' and 'string' tables. There are also some special features using metatables to allow the double syntax 'cas.oper(exp)' / 'exp:oper()' for any function owned by the cas table.What exactly does the cas function?

Wow, this is not a small piece of code. I think I will really have to write a software to exchange Lua programs between the CP and the computerRumberg Integration Function ( Code ):

I must say that I have some small problems when writing the results of CAS operations in the console window, because there are sometimes characters that are not yet supported by this basis version. But don't worry, it's not definitive I'm also thinking about the possibility to show results in a "2D" form, and not linear. However I don't know yet how I will implement the 'input' operations

Posted 09 September 2005 - 04:00 PM

He's still one of the persons that are the most interested in Lua (like you, PAP), and I must thank him for thatGood start, anyway...

I think a little time is needed to discover all the Lua possibilities though

Posted 09 September 2005 - 04:00 PM

I'm afraid I don't agree. Romberg integration is accurate, but using a fixed nuber of N is definitely not the best choice. You cannot get a very accurate result this way, unless you integrate simple functions.

yes ,you are right , it just integrate simple functions !!!

I,m waiting for the must structured one ! thanks a lot .

Posted 09 September 2005 - 04:38 PM

You can add many things with "libraries", though, and this is some kind of language extension. Good news.I have complete control on the Lua "libraries", however I can't change anything to the language itselfs, or to the syntax.

Implementing the sign() functions is easy, I will do it immediatly (there will be a math.sign() function which takes one or 2 arguments).

As you can see from the examples, Fortran 95 is aConcerning the other functions they seem to principaly do manipulations on arrays, and there are indeed no appropriate functions for it. Maybe I will create a "array" library with this kind of functions, like the existing "table" library (which can be used for tables manipulation).

That's why I said that Lua is a good choice for a calculator, but I will never use it on my computer, given that I'm programming in Fortran 95. I'm not complaining at all, Lua has some kind of optional arguments, and this is impressive for a language that can be used on a calculator.However I won't be able to implement the "named" optional arguments, since it is a limitation of the Lua language itselfs.

This is not absolutely necessary, but it is a nice feature. If implemented, we could have something similar to the "PrintNatural" command.I'm also thinking about the possibility to show results in a "2D" form, and not linear.

Well, in my native language there is a proverb which says: "the beginning is the half of the whole thing" --- it means that starting to learn something is the most important step. You have taken this step succesfully. You are already able to write numerical analysis programs, and you should be proud of it! But you must keep learning, as everybody... nobody was able to write structured programs from the beginning.yes ,you are right , it just integrate simple functions !!!

Posted 09 September 2005 - 04:57 PM

Please, leave the precision as it is now. As you said, limited precision is a common "problem". For example, try 1+1e-16 in Lua. You will get... 1 (exactly one). I wrote a small Lua problem, in order to find the smallest number which can be added to 1 and give something different to one (this number is often called "epsilon"). I have found that ClassPad internal arithmetics has epsilon=1.12e-16 (correct to 2 decimal digits). It's not bad at all (and it's a common value in 32-bit computers). Btw, Fortran 95 has a function epsilon(x) which returns that number in precision same as the argument x .Thus math.rad(180) gives the PI number as result, but since the interpreter use double as type when manipulating numbers the precision is not perfect, and sin(u) returns 1.22e-16 and not exactly zero.

This is a common problem... If you really need it I could try to use the native BCD type of the classpad to ensure perfect precision, but i'm afraid it will slow down the execution

Everyone who uses computers must live with limited precision. "Perfect" precision will certainly slow down the execution, and it is not really needed in numerical analysis.

Posted 09 September 2005 - 05:34 PM

I just realized that array support in Lua is primitive (as in C): you need loops for everything. For example, if you want to calculate B=A-x, where A is a vector and x is a scalar, you must write something like:

B=A for i=1,table.getn(A) B[i]=A[i]-x endYou need a loop even to print the elements of a vector! This is really annoying, and makes programs very lengthy. Maybe the "array library" you are planning should start from these simple tasks.

Posted 09 September 2005 - 06:07 PM

The table library provides some useful functions for it

For example if you wan to 'print' all the elements of the table 'tab', you can write

For example if you wan to 'print' all the elements of the table 'tab', you can write

table.foreach(tab,print)But you're right, as Lua is based on a strict C interface it is quite similar to it, with some good and some other "not so good" features

Posted 09 September 2005 - 06:29 PM

table.foreach prints in its own way, which is not satisfactory. Since numerical methods are full of matrix operations, I will need to write loops for everything (not just printing). Really annoying, since I'm accustomed with excellent matrix support in Fortran 95 . Let's face it, C/C++ hasThe table library provides some useful functions for it

For example if you wan to 'print' all the elements of the table 'tab', you can writetable.foreach(tab,print)But you're right, as Lua is based on a strict C interface it is quite similar to it, with some good and some other "not so good" features

Posted 09 September 2005 - 07:26 PM

If I can create a "CAS expression" type in Lua (given by cas.expr()) and define the arithmetic operators for it, I can also make a new "Matrix" type with special operators and methods

You could even create this type by yourself, using Lua's metatables system

Naturally if I "hard-code" it in C (like the CAS operations) it will get a bit faster, but you should be able to do the first steps in lua (that is, define the +,-,*,/,<,>,= operations etc)

Take a look on the following:

You could even create this type by yourself, using Lua's metatables system

Naturally if I "hard-code" it in C (like the CAS operations) it will get a bit faster, but you should be able to do the first steps in lua (that is, define the +,-,*,/,<,>,= operations etc)

Take a look on the following:

Source: http://www.lua.org/m...manual.html#2.8Every table and userdata object in Lua may have a metatable. This metatable is an ordinary Lua table that defines the behavior of the original table and userdata under certain special operations. You can change several aspects of the behavior of an object by setting specific fields in its metatable. For instance, when an object is the operand of an addition, Lua checks for a function in the field "__add" in its metatable. If it finds one, Lua calls that function to perform the addition.

Posted 09 September 2005 - 10:09 PM

the Basic "PrintNatural" command show the results in a separate window , I think it is not so good and I,m sure you do not mean that, If we could have 2D form in the output screenPAP : 2D form is not absolutely necessary, but it is a nice feature. If implemented, we could have something similar to the "PrintNatural" command

whitin :

scrollable MathWindow, TabArrow MathWindow , sliding Mathwindow

it would be really nice , I think a good program should have a good user Interface which make it more easer to read , work , understand,..

a good user Interface will make the Cplua a very nice , easy to understand , easy to use , fast ,...

language for a calculator , which was not avialable in the past !

except SDK , but SDK uses c ,c++ language , which I,m a beginner with it . and it is really hard to become a good c++ programmer ,

it takes lots of time , which is valuable for me.

because I,m a university student , and I do not have enough time to study c++ language .

but Lua is so interesting and I think it is as simple as possible ,

---------------------------------------------------------------------------

adding the needed functions to Lua is a good Idea .

Imagine the time that we could have all the neccesary functions in the library and all the SDK features in Lua , WOW . It will be really really interesting .

Posted 09 September 2005 - 11:10 PM

Hmmm. Time to learn metatables.Naturally if I "hard-code" it in C (like the CAS operations) it will get a bit faster, but you should be able to do the first steps in lua (that is, define the +,-,*,/,<,>,= operations etc)

Take a look on the following:

Source: http://www.lua.org/m...manual.html#2.8

This implementation of "operators" is strange, at least for me (in Fortran 95 it's much more easier). With or without metatables, however, you have to "reinvent the wheel", if you need matrix support in C++ or Lua : defining basic matrix operations from scratch is a headache, and it's like trying to reinvent the wheel . I need a lot of work just for the basics. I'll try to live with that, but the fact remains: C++ and Lua have a very basic, primitive, and innacceptable matrix support.

Posted 10 September 2005 - 12:29 AM

C++ and Fortran do not have the same purposes...

I never used Fortran but I often used Matlab, which is another math (and matrix) oriented language, and you certainly know it. So I think I can see what kind of features you want.

But I'm a C++ programmer, it is still my favorite language and I use it everyday. I must say that the common mathematic tools provided by C++ are quite enough for a huge part of the applications written with it. If you want to implement some complex numeric methods for mathematic analysis, then it is a normal to use a specific language like Fortran. Otherwhise, a powerful, general language as C++ will certainly be more useful.

So don't blame C++ for its lack of specific features like math tools etc: it was not designed for it. It's like if you were complaining that you cannot cross the sea with your car I enjoy the power of this language everyday, and I would certainly not want it to be slowed down because it provides some special features that most programmers will never use.

C++ was**not **designed for numeric analysis. That's all.

I never used Fortran but I often used Matlab, which is another math (and matrix) oriented language, and you certainly know it. So I think I can see what kind of features you want.

But I'm a C++ programmer, it is still my favorite language and I use it everyday. I must say that the common mathematic tools provided by C++ are quite enough for a huge part of the applications written with it. If you want to implement some complex numeric methods for mathematic analysis, then it is a normal to use a specific language like Fortran. Otherwhise, a powerful, general language as C++ will certainly be more useful.

So don't blame C++ for its lack of specific features like math tools etc: it was not designed for it. It's like if you were complaining that you cannot cross the sea with your car I enjoy the power of this language everyday, and I would certainly not want it to be slowed down because it provides some special features that most programmers will never use.

C++ was

I didn't say that you had to create everything by yourself. There are certainly some other programmers like you, who found that C++ is not quite suitable for math and who wrote some useful classes and functions that we could re-use in CPLua.defining basic matrix operations from scratch is a headache, and it's like trying to reinvent the wheel . I need a lot of work just for the basics.

Posted 10 September 2005 - 02:15 AM

So how compatible is Cplua with other flavors, and are there open source libraries for Cplua?I didn't say that you had to create everything by yourself. There are certainly some other programmers like you, who found that C++ is not quite suitable for math and who wrote some useful classes and functions that we could re-use in CPLua.

Posted 10 September 2005 - 09:44 AM

Well... As long as we want to integer some "Classpad-compatible" features, I think it should be possible The problems come by the input/output operations which need some adaptations (mainly because there is no standard output on Classpad like on most other systems, or because we must use MCS files etc). We should be able to use any code written in Lua for other platforms, as long as the Lua libraries and functions that it uses have been correctly ported to CP.

As I said I could also add some utility functions written in C++ or C (like a Matrix class etc), and create Lua functions to provide direct access to it (like what I'm currently doing with the CAS).

Unfortunately CPLua is not quite modulable for now... Adding new functionalities is not that easy, and I would like to reorganize my source code a little bit before releasing it.

As I said I could also add some utility functions written in C++ or C (like a Matrix class etc), and create Lua functions to provide direct access to it (like what I'm currently doing with the CAS).

Unfortunately CPLua is not quite modulable for now... Adding new functionalities is not that easy, and I would like to reorganize my source code a little bit before releasing it.

Posted 10 September 2005 - 12:07 PM

If you use Matlab, you know what I want (actually, matrix support in Matlab is directly copied from Fortran 95). I'm not asking for all Matlab's features, I just need decent matrix support.I never used Fortran but I often used Matlab, which is another math (and matrix) oriented language, and you certainly know it. So I think I can see what kind of features you want.

In C++ (and, unfortunately, in Lua too), matrix support is not even elementary. It's primitive. You can say that matrix support does not even exist in these languages. Disappointing.

If by the term "common mathematic tools" you mean simple arithmetics (basic operations, elementary functions), you are right. But I don't understand your statement about "complex" numerical methods: A matrix is definitely an elementary mathematical structure, there is nothing "complex" on it. In the majority of numerical methods, matrix operations are heavily used. But most of these methods are not complex at all.I must say that the common mathematic tools provided by C++ are quite enough for a huge part of the applications written with it. If you want to implement some complex numeric methods for mathematic analysis, then it is a normal to use a specific language like Fortran.

I know, I know. C++ was designed for writing operating systems, windows applications, stuff like that. It's powerful for this, but it's nothing if you want to develop a program where even elementary mathematics are involved. I'm not blaming C++. I simply don't need it.So don't blame C++ for its lack of specific features like math tools etc: it was not designed for it.

CPLua seems to be the most promising project in ClassPad, since Lua is much more powerful than CP Basic. That's why I'm interested on this project. However, its primitive matrix support is a great disadvantage for me. It is a pity, because otherwise Lua is very powerful for a calculator.

I strongy disagree with that statement. First, matrix support is not a "special feature". You don't need it, so you are obviously enjoying the "power" of C++, and you do well (afterall, you can develop this project in C++, and this project is definitely useful). Second, don't be so sure that "most" programmers will never use such "special features". I don't think that I am a programmer that needs "special features", just because I need decent matrix support. Afterall, I want a programming language for ClassPad, which is supposed to be a mathematical tool, and matrices play a major role in mathematics.I enjoy the power of this language everyday, and I would certainly not want it to be slowed down because it provides some special features that most programmers will never use.

Anyway, I'm not here to discuss which programming language is the "best". For you, it's C++, for me it's not. No problem. I'm here to help the developement of this project, and I think that I may have something useful to say about the future developement of the project. Now, as a developer, you must take a serious decision: CPLua will or will not be useful in mathematical applications? The choice is yours, but let us know.

Btw, maybe it's possible to add matrix operations by using the CAS. ClassPad's CAS has not a powerful matrix support, but it's better than nothing. Is it possible to make use of the matrix support that the CAS provides in Lua?

Posted 10 September 2005 - 12:41 PM

When I first told you that I was working on a new project that could be interesting for you, I naturally meaned that it could be useful in those kind of applications. I will do what I can, but there are different priorities...CPLua will or will not be useful in mathematical applications? The choice is yours, but let us know.

CPLua's develoment will be long and continuous, as long as people ask for new features there is no reason to refuse it (except for unrealizable thing, I do not want to try to create Lua functions for OpenGL )

I didn't see anything about thatBtw, maybe it's possible to add matrix operations by using the CAS. ClassPad's CAS has not a powerful matrix support, but it's better than nothing. Is it possible to make use of the matrix support that the CAS provides in Lua?

The SDK documentation about CAS is very very poor, there is only the strict minimum and it won't be easy to find how to exploit all the possibilities. But at least as I wanted to show with my last screenshots, Lua is not an obstacle for it

Posted 10 September 2005 - 12:48 PM

I'm afraid that I cannot understand the scope of variables in a Lua "chunk" that is loaded by doscript or loadfunc. Here is a problem I have encountered during the developement of the Romberg method in CPLua:

Suppose that you have a "main" Lua program that calls a function named foo, which is loaded by loadfunc("Romberg/foo"). Now suppose that function foo calls another function, named subfoo, which is loaded by loadfunc("LuaUtils/subfoo"). I want that function to be local to foo, so that the "main" program does not "know" and cannot call the function subfoo. If I declare the function subfoo as

Suppose that you have a "main" Lua program that calls a function named foo, which is loaded by loadfunc("Romberg/foo"). Now suppose that function foo calls another function, named subfoo, which is loaded by loadfunc("LuaUtils/subfoo"). I want that function to be local to foo, so that the "main" program does not "know" and cannot call the function subfoo. If I declare the function subfoo as

local function subfoo(a,b) ... code ... endthen this function cannot be used, even by foo: it report "attempt to call global 'subfoo' (a nil value)". Now, if I declare the function subfoo as

function subfoo(a,b) ... code ... endthen it works, but subfoo can be called by the "main" program. If foo contains a declaration local subfoo, then subfoo cannot be used. The same problem occurs if I replace loadfunc with doscript. I seems that every loaded function should be global, but I cannot realize why. Maybe I'm doing something wrong?

Posted 10 September 2005 - 12:54 PM

You are right, any function is supposed to become global when it is loaded. It's a bit primitive, but I don't think this is a real problem for now

Posted 10 September 2005 - 12:55 PM

By the way, if you don't want to load too many global functions (to avoid name pollution etc), you can also create your own table with a set of lua functions

0 members, 0 guests, 0 anonymous users