1 страниц (8 вхождений)
Functions behave differently in 0.9 - Сообщения
#1 Опубликовано: 13.01.2012 04:37:32
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.
[LIVE width=200 height=700]http://smath.info/live/?file=3439[/LIVE]
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.
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.
[LIVE width=200 height=700]http://smath.info/live/?file=3439[/LIVE]
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.
Ed
#2 Опубликовано: 13.01.2012 15:54:26
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:
[MATH=eng]y←5[/MATH]
[MATH=eng]f(x)←line(y←y+x,y,2,1)[/MATH]
[MATH=eng]f(3)=8[/MATH]
[MATH=eng]y=5[/MATH]
This is the right behavior. Value of y should remain unchanged.
Now, just do the page recalculation or press F9
[MATH=eng]y←5[/MATH]
[MATH=eng]f(x)←line(y←y+x,y,2,1)[/MATH]
[MATH=eng]f(3)=8[/MATH]
[MATH=eng]y=8[/MATH]
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
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:
[MATH=eng]y←5[/MATH]
[MATH=eng]f(x)←line(y←y+x,y,2,1)[/MATH]
[MATH=eng]f(3)=8[/MATH]
[MATH=eng]y=5[/MATH]
This is the right behavior. Value of y should remain unchanged.
Now, just do the page recalculation or press F9
[MATH=eng]y←5[/MATH]
[MATH=eng]f(x)←line(y←y+x,y,2,1)[/MATH]
[MATH=eng]f(3)=8[/MATH]
[MATH=eng]y=8[/MATH]
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
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#3 Опубликовано: 13.01.2012 21:44:13
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.
Best regards, Andrey Ivashov.
#4 Опубликовано: 13.01.2012 21:51:24
You are welcome,
BTW, I also reproduced a problem with 3D graphs when recalculating page (F9) http://ru.smath.info/forum/default.aspx?g=posts&m=5914#post5914. The axis moved after subsequent pressing of F9.
Regards,
Radovan
BTW, I also reproduced a problem with 3D graphs when recalculating page (F9) http://ru.smath.info/forum/default.aspx?g=posts&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!"
#5 Опубликовано: 14.01.2012 02:56:58
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.
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.
1 пользователям понравился этот пост
Fridel Selitsky 14.01.2012 05:10:00
#6 Опубликовано: 14.01.2012 21:11:44
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:
[MATH=eng]x←1[/MATH] [MATH=eng]d←8[/MATH]
[MATH=eng]f(xVar)←line(xVar←xVar+5,d←7,mat(xVar,d,2,1),3,1)[/MATH]
[MATH=eng]f(x)=mat(6,7,2,1)[/MATH]
[MATH=eng]x←1[/MATH] [MATH=eng]xVar←#[/MATH]
[MATH=eng]d=7[/MATH]
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?
[MATH=eng]x←1[/MATH] [MATH=eng]d←8[/MATH]
[MATH=eng]f(xVar)←line(xVar←xVar+5,d←7,mat(xVar,d,2,1),3,1)[/MATH]
[MATH=eng]f(x)=mat(6,7,2,1)[/MATH]
[MATH=eng]x←1[/MATH] [MATH=eng]xVar=6[/MATH]
[MATH=eng]d=8[/MATH]
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?
[MATH=eng]x←1[/MATH] [MATH=eng]d←8[/MATH]
[MATH=eng]f(x)←line(x←x+5,d←7,mat(x,d,2,1),3,1)[/MATH]
[MATH=eng]f(x)=mat(6,7,2,1)[/MATH]
[MATH=eng]x←6[/MATH]
[MATH=eng]d=8[/MATH]
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:
[MATH=eng]x←1[/MATH] [MATH=eng]d←8[/MATH]
[MATH=eng]f(xVar)←line(xVar←xVar+5,d←7,mat(xVar,d,2,1),3,1)[/MATH]
[MATH=eng]f(x)=mat(6,7,2,1)[/MATH]
[MATH=eng]x←6[/MATH] [MATH=eng]xVar←#[/MATH]
[MATH=eng]d=8[/MATH]
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]
[MATH=eng]line(arg=30,param=40,2,1)[/MATH]
there were always symbolical equal to in the tooltips or the Dynamic assistance.
[MATH=eng]line(arg—30,param—40,2,1)[/MATH]
Is there any new feature there introduced maybe?
Regards,
Radovan
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:
[MATH=eng]x←1[/MATH] [MATH=eng]d←8[/MATH]
[MATH=eng]f(xVar)←line(xVar←xVar+5,d←7,mat(xVar,d,2,1),3,1)[/MATH]
[MATH=eng]f(x)=mat(6,7,2,1)[/MATH]
[MATH=eng]x←1[/MATH] [MATH=eng]xVar←#[/MATH]
[MATH=eng]d=7[/MATH]
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?
[MATH=eng]x←1[/MATH] [MATH=eng]d←8[/MATH]
[MATH=eng]f(xVar)←line(xVar←xVar+5,d←7,mat(xVar,d,2,1),3,1)[/MATH]
[MATH=eng]f(x)=mat(6,7,2,1)[/MATH]
[MATH=eng]x←1[/MATH] [MATH=eng]xVar=6[/MATH]
[MATH=eng]d=8[/MATH]
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?
[MATH=eng]x←1[/MATH] [MATH=eng]d←8[/MATH]
[MATH=eng]f(x)←line(x←x+5,d←7,mat(x,d,2,1),3,1)[/MATH]
[MATH=eng]f(x)=mat(6,7,2,1)[/MATH]
[MATH=eng]x←6[/MATH]
[MATH=eng]d=8[/MATH]
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:
[MATH=eng]x←1[/MATH] [MATH=eng]d←8[/MATH]
[MATH=eng]f(xVar)←line(xVar←xVar+5,d←7,mat(xVar,d,2,1),3,1)[/MATH]
[MATH=eng]f(x)=mat(6,7,2,1)[/MATH]
[MATH=eng]x←6[/MATH] [MATH=eng]xVar←#[/MATH]
[MATH=eng]d=8[/MATH]
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]
[MATH=eng]line(arg=30,param=40,2,1)[/MATH]
there were always symbolical equal to in the tooltips or the Dynamic assistance.
[MATH=eng]line(arg—30,param—40,2,1)[/MATH]
Is there any new feature there introduced maybe?
Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#7 Опубликовано: 14.01.2012 23:06:09
Thank you for the comment. Correct example you have shown is the last one:

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.

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.
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.
Wroteif 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.
WroteI 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.
WroteOn the other hand, I see for the first time this in the tooltip (using numerical equal to)

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.
#8 Опубликовано: 15.01.2012 00:51:05
Hello Andrey,
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
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).
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
WroteThank 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

WroteWroteOn the other hand, I see for the first time this in the tooltip (using numerical equal to)
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
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
1 страниц (8 вхождений)
-
Новые сообщения
-
Нет новых сообщений