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 TheWizEd  
#1 Posted : 13 January 2012 11:37:32(UTC)
TheWizEd


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2010(UTC)
Posts: 178
Man
United States

Was thanked: 19 time(s) in 13 post(s)
Two things I've noticed about functions for the new SMath 0.9 version.

It appears global variables are used in functions by value. Notice the last case. Even though y is redefined in the function outside the function its the original value.

And in the previous version 0.89 you could define a variable within a function and use the variable outside the function this is no longer the case.

Open in SMath Cloud

I've also discovered that a complex function that ran well under 0.89 seems to run forever on 0.90. I'm trying to determine the cause and will let everyone know what I find.

Edited by user 13 January 2012 13:20:23(UTC)  | Reason: Not specified

Ed

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

Offline omorr  
#2 Posted : 13 January 2012 22:54:26(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 Ed,

I think this behavior regarding local variables in multiline functions has been introduced in v0.89.8. In my opinion it seems better to have locally defined variables inside function definitions. In the same version the function name has been put on the top, not in the middle like in 0.89.

On the other hand, it seems in v.0.90 has been introduced a bug regarding this.
Try a simple example:

y←5
f(x)←line(y←y+x,y,2,1)
f(3)=8
y=5

This is the right behavior. Value of y should remain unchanged.
Now, just do the page recalculation or press F9

y←5
f(x)←line(y←y+x,y,2,1)
f(3)=8
y=8

Value of y has changed and this is wrong. Please try to reproduce this. If you can do this as well, this is definitely a bug.
Beta version v.0.89.8 will work correctly and will keep the value of y unchanged after page recalculation.

Regards,
Radovan

Edited by user 14 January 2012 01:28:10(UTC)  | Reason: Not specified

When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
Offline Andrey Ivashov  
#3 Posted : 14 January 2012 04:44:13(UTC)
Andrey Ivashov


Rank: Administration

Groups: Developers, Registered, Knovel Developers, Administrators, Advanced Member
Joined: 11/07/2008(UTC)
Posts: 1,616
Man
Russian Federation

Was thanked: 1978 time(s) in 666 post(s)
You are right. Thank you for figuring this out. I've already found a reason and will fix it soon. Will try to release updated SMath Studio as soon as possible.

Best regards, Andrey Ivashov.
Offline omorr  
#4 Posted : 14 January 2012 04:51:24(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)
You are welcome,

BTW, I also reproduced a problem with 3D graphs when recalculating page (F9) http://ru.smath.info/for...osts&m=5914#post5914. The axis moved after subsequent pressing of F9.

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
Offline Andrey Ivashov  
#5 Posted : 14 January 2012 09:56:58(UTC)
Andrey Ivashov


Rank: Administration

Groups: Developers, Registered, Knovel Developers, Administrators, Advanced Member
Joined: 11/07/2008(UTC)
Posts: 1,616
Man
Russian Federation

Was thanked: 1978 time(s) in 666 post(s)
Regarding local variables...

I'm absolutely agree that local variables must be invisible from outside of the function, but I found that this is a huge problem for some functionality like graphs animation, because after the first step (first frame calculation) we need to store some temporary data generated and this data required for the second step. In version 0.90 of SMath Studio this temporary data for graph animations was defined outside the function and animation works there because of the bug you found. After I've made a fix for local variables visibility, animation became broken...

So, I needed some new approach for data transferring and... here is my solution:


Now we have an ability to modify incoming arguments values! I think this is a great enhancement for the program. As you see on the screenshot global variables now can even be defined inside the function using this method. And I've tested hundreds of already created files (automated tests of course) - nothing changed for the existing worksheets (except ones with animated graphs, but only thing needed to fix them is to add variables used inside the function as an arguments - very minor fix)!

Need to do some other stuff before next release, but still hope to create new version in a week or about.

Best regards, Andrey Ivashov.

Edited by user 14 January 2012 10:00:01(UTC)  | Reason: Not specified

thanks 1 user thanked Andrey Ivashov for this useful post.
on 14/01/2012(UTC)
Offline omorr  
#6 Posted : 15 January 2012 04:11:44(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)
Thank you Andrey,

Let me get this straight in order to figure out how would that be working.
This is the bahavior in v0.90 which is a bug introduced due to new animate feature:

x←1 d←8
f(xVar)←line(xVar←xVar+5,d←7,mat(xVar,d,2,1),3,1)
f(x)=mat(6,7,2,1)
x←1 xVar←#
d=7

1. Global variable "d" has changed from 8 to 7 (after F9) and it should not be this way - wrong.
2. Variable "x" is a real function argument in the function call and the global variable with the same name "x" has not change - correct.
3. Variable "xVar" is a variable in the function definition list and is changed inside the function definition. It is not known outside the function definition.

Now, let me do sam [FACKED] examples by changing the output here in the forum (this is not an actual output from v0.90)

- The fixed first example should give this output - if I was right?
x←1 d←8
f(xVar)←line(xVar←xVar+5,d←7,mat(xVar,d,2,1),3,1)
f(x)=mat(6,7,2,1)
x←1 xVar=6
d=8

1. The global variable "d" has not changed in spite of changing the local variable with the same name inside the function definition - correct.
2. The new global variable "xVar" has been defined inside the function.
3. The variable "x" as an argument in the function calling has not been changed - correct

- The fixed second example should give this output - if I was right?
x←1 d←8
f(x)←line(x←x+5,d←7,mat(x,d,2,1),3,1)
f(x)=mat(6,7,2,1)
x←6
d=8

1. The fictive argument "x" will be changed only if there are the same name of arguments in the function definition (and changed inside the function body)
2. Any other variable which are defined locally (including the same name as outside the definition) and not present in the function definition list will remained unchanged

I hope I am right about all of this. If not, please let me know. However, if this is working as described I think this would be just fine.

However I think that I was not right about this ant the real changes are like this:

x←1 d←8
f(xVar)←line(xVar←xVar+5,d←7,mat(xVar,d,2,1),3,1)
f(x)=mat(6,7,2,1)
x←6 xVar←#
d=8

1. Argument "x" has changed because its changing inside the function definition (passing by reference)
2. Variable "d" has not changed due to the locally definition inside the function body.

This behavior is also acceptable. If the "passing by reference" is introduced there is a trick if we do not want to change the real function argument - by passing something like "1*x" or "0+x" instead of "x". At least I hope it will work that way - not sure.
The worst thing would be if we allow the variable "d" to be changed inside the function body and retain its value afterwards.
I think there are no to many situation where we need to change the function arguments in the function definition. One of this situation is in recursive function calls. I am not quite sure about its working in v.0.90. (see this post please recursive function call)

On the other hand, I see for the first time this in the tooltip (using numerical equal to)
[FACKED]
line(arg=30,param=40,2,1)

there were always symbolical equal to in the tooltips or the Dynamic assistance.

line(arg—30,param—40,2,1)

Is there any new feature there introduced maybe?


Regards,
Radovan

Edited by user 15 January 2012 04:40:06(UTC)  | Reason: Not specified

When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
Offline Andrey Ivashov  
#7 Posted : 15 January 2012 06:06:09(UTC)
Andrey Ivashov


Rank: Administration

Groups: Developers, Registered, Knovel Developers, Administrators, Advanced Member
Joined: 11/07/2008(UTC)
Posts: 1,616
Man
Russian Federation

Was thanked: 1978 time(s) in 666 post(s)
Thank you for the comment. Correct example you have shown is the last one:


omorr wrote:
if we do not want to change the real function argument - by passing something like "1*x" or "0+x" instead of "x"

I think if one don't want to change the argument new variable should be defined inside the function's body (local variable) with that argument.


omorr wrote:
I think there are no to many situation where we need to change the function arguments in the function definition.

I found that introducing this feature is the only one solution for such complex situation like animated Graphs.

It also allow to create functions with absolutely hidden from user logic and without any global variables used. And note that in the example below user is able to choose a name of the steps variable by himself - no need to redefine anything!


As for me, I'm very exited for these feature - it is a very helpful thing when I'm working with complex logic.

omorr wrote:
On the other hand, I see for the first time this in the tooltip (using numerical equal to)

Good Yes! Please see the screenshot below:


As you can see we can get three different results for the same left part (in next version of course). So, I'm thinking: should I introduce new operator for substitution only results (because numeric and symbolic results have its own operators) or, maybe, it's easier to unify all results with the same operator? Shortcuts will be the same but it is only equal sign will be shown everywhere... as in a real math.

Best regards, Andrey Ivashov.

Edited by user 15 January 2012 06:31:37(UTC)  | Reason: Not specified

Offline omorr  
#8 Posted : 15 January 2012 07:51:05(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 Andrey,
smath wrote:
Thank you for the comment. Correct example you have shown is the last one:

I see. It is then "passing by reference" function arguments. I understood your points and agree with them. If there is more potential benefit for SMath including this feature, just go for it Good There would be no much problem about it and the user just have to be aware of that - nothing else. On the other hand, as soon as I posted the comment it crossed my mind the same possible additional feature you presented with the ChordMethod() function example. Besides the great ability of SMath to have the same function name with different number of arguments, there would be another one useful in the next release. The function could then return results in two ways. The first one is by the last assigned variable at the end of the function body (as it now) and the second one would be via function arguments. Some of the function arguments are strictly input (assigned before and not changed inside the function), input-output (assigned before and changed inside the function) and strictly output (not assigned before and get value inside the function) -the last one is your example regarding "steps" variable in ChordMethod() function. I am not a programmer but this logic is present in many programming languages (like pointers in C or something else).
smath wrote:
omorr wrote:
On the other hand, I see for the first time this in the tooltip (using numerical equal to)

Good Yes! Please see the screenshot below:


As you can see we can get three different results for the same left part (in next version of course). So, I'm thinking: should I introduce new operator for substitution only results (because numeric and symbolic results have its own operators) or, maybe, it's easier to unify all results with the same operator? Shortcuts will be the same but it is only equal sign will be shown everywhere... as in a real math.

I did not understood you well, sorry. I do not understand how did you manage to get the first result of "A" in your example. I suppose this would be a new feature - very interesting and quite useful some time. It crossed my mind many times how to get the result in this way. As far as I am concerned I would agree with the most easier way for you to accomplish. Regarding the replacing the "equal signs" there is a nice feature in the Page Setup to replace all of them with "=" sign on the final print out. I would just be satisfied if there would be a similar option just to replace all of them in the worksheet on the screen at once (just to see them on the screen). If the option is active we would see everywhere "=" signs. If we click inside the math region there would see the real operator. There is an option in Mathcad to replace the operators of every math region, but as I remember I rarely used that - it might be confusing for the students at the beginning. For instance, if the "=" is active we could type the real operator or shortcut and as long as we are inside the the math region we could see it. If we leave it - the "=" will appear. On the other hand, tooltips and Dynamic asistance will have "=" instead of symbolic aqual to until this option is active. I do not know if this have any sense - just my thoughts.

Regards,
Radovan

Edited by user 15 January 2012 07:57:49(UTC)  | Reason: Not specified

When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
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.