Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Login


Options
Go to last post Go to first unread
Offline jabadu  
#1 Posted : 27 May 2012 11:56:03(UTC)
jabadu


Rank: Advanced Member

Groups: Registered
Joined: 10/11/2010(UTC)
Posts: 37
Location: Germany

Was thanked: 1 time(s) in 1 post(s)
Hello,

I found 2 strange behaviors / bugs with matrix handling.

matrix-bug.jpg

On the left side of the picture you see some operations with extracting and overwriting cells. All works fine except to the last few lines.

On the right side I get an error message but the code still works fine. I don't know what is wrong with this code (maybe the bug is the user here ;-).

It seems that this behavior is all the same in the 0.9x series of SMATH, in 0,89 the left side works fine but not the right side.

I use SMATH 0,94 build 4523 on linux.

Can anyone check this and confirm? Here is the SMATH file: matrix-bug.sm.zip

Edited by moderator 29 May 2012 01:48:15(UTC)  | Reason: Not specified

Wanna join the discussion?! Login to your SMath Studio Forum forum account. New Registrations are disabled.

Offline omorr  
#2 Posted : 27 May 2012 15:16:20(UTC)
omorr


Rank: Administration

Groups: Registered, Advanced Member
Joined: 23/06/2009(UTC)
Posts: 1,740
Man
Serbia

Was thanked: 318 time(s) in 268 post(s)
Hello,

I think there is some kind of misunderstanding here. There is a mistake to define variables in this way and both definitions of variables are incorrect (result and result2). You can see that by hovering the mouse over them. You should define variables like this:


line(k:0,for(i,range(1,length(X)),line(k:k+1,el(result,k):el(X,i)*el(Y,i),2,1)),result,3,1)

and


for(i,range(1,length(X)),el(result2,i):el(X,i)+el(Y,i))

Additional result:= and result2:= in front of these constructions are making a mess.
Regarding the first one here are the pictures. Lines are like vector elements.





In the second one the for loop is executing but the assignment is incorrect, therefore the syntax error.



Regards,
Radovan

Edited by user 27 May 2012 15:21:06(UTC)  | Reason: Not specified

When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
Offline jabadu  
#3 Posted : 27 May 2012 18:24:36(UTC)
jabadu


Rank: Advanced Member

Groups: Registered
Joined: 10/11/2010(UTC)
Posts: 37
Location: Germany

Was thanked: 1 time(s) in 1 post(s)
Hi,

thanks for the quick answer. It works now without any errors. So, this time the bug was the stupid user Sad

There is something irritating that even though the definition is wrong, the result will still be calculated correctly.

Offline mkraska  
#4 Posted : 27 May 2012 21:50:08(UTC)
mkraska


Rank: Advanced Member

Groups: Registered
Joined: 15/04/2012(UTC)
Posts: 1,988
Germany

Was thanked: 1126 time(s) in 723 post(s)
Originally Posted by: jabadu Go to Quoted Post
Hi,

thanks for the quick answer. It works now without any errors. So, this time the bug was the stupid user Sad

There is something irritating that even though the definition is wrong, the result will still be calculated correctly.



Hi,

I tried to understand what happened in the example. My current guess is:

The operations

k:0

result:line(for(i;range(1;length(X));line(k:k+1;el(result;k):el(X;i)*el(Y;i);2;1));result;2;1)

use result to store the line structure of expressions symbolically. Whenever evaluation is requested by the = operator, then the stored expression is evaluated using the current value of all variables involved in the definition. Assignment to "result" just changes the definition.

If the : Operator is meant to assign the evaluated result of some expression, then eval() has to be used. Any later change of variables used in the expression do not affect the content the formerly evaluated result.

In both cases nothing seems to be wrong with using the same variable name as return value for the line operator and as target for the expression assignment. Replacing result by result1 inside the expression has no effect on the behavior (at least in this small example). This might be due to that the line operator shields parameter arguments in function definitions and return values from global name space

result:eval(line(k:1;for(i;range(1;length(X));line(k:k+1;el(result;k):el(X;i)*el(Y;i);2;1));result;3;1))

If you try to assign the for operator to a variable, this fails.

result2:for(i;range(1;length(X));el(result1;i):el(X;i)+el(Y;i))

result2 is undefined, result1 contains the expected vector.

Based on that guess I would propose the following:
  • More specific error message (e.g. "Assignment of for statement is ignored" ) in the result2 case.
  • Disabling of assignment to elements of line structures unless it is meant to edit or automatically generate them. In that case assignment of assignment expressions like el(result;1):k:2 or similar statements should be possible ;-)


Martin

Martin Kraska

Pre-configured portable distribution of SMath Studio: https://smath.com/wiki/SMath_with_Plugins.ashx
thanks 2 users thanked mkraska for this useful post.
on 28/05/2012(UTC),  on 28/05/2012(UTC)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.