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

Notification

Icon
Error

Login


2 Pages<12
Options
Go to last post Go to first unread
Offline omorr  
#21 Posted : 31 July 2010 11:19:51(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,
omorr wrote:

I just need to put say g(x,f(a)) and it will work. The variable "a" must not be previously defined - The result would be zero then ...-

I was just playing with this feature in v0.89 in order to make some Wiki pages about it. Here is the example to the other users, just in case to clarify things.

Here is the function definition of "f" with two arguments- one of the argument is variable and another is function "F" (argumet function) - with single argument
f(x,F(1))←F(x+2)
On the LHS of the definition F(1) means that argument function F has one argument (I prefer this way) although it could be defined as F(dummy) where "dummy" might be whatever we like - it does not matter.
Let's put some variables and functions here
a←6
x←mat(1,3,2,1)
fun(y)←y
fun1(z)←z+a
Now, few calls of function "f"
f(x,fun(xx))=mat(3,5,2,1)
f(x,fun1(xx))=mat(9,11,2,1)
It must be taken care that arguments of argument function "fun" and "fun1" have the following restrictions:
1. constants not allowed (like fun(5))
2. must be a variable different that the name of arguments in the function "f" (fun(x) not allowed here - x is the argument of "f" )
3. also the name of previously defined variable is not allowed (f(a) not allowed - variable "a" is defined above)

I hope this is Ok.

Regards
Radovan

P.S. I think this is not possible (it would be quite to much at the moment Good )
F(x,y,U(x,f(1)))←U(x,f(x))+2
Could you confirm this, please. This would be another restriction, but might be logical from the SMath implementation - not sure?
4. Argument function "U" in the argument list of "F" can not have another argument function in the argument list - "f(1)"

Edited by user 31 July 2010 11:22:35(UTC)  | Reason: Not specified

When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
Offline omorr  
#22 Posted : 08 August 2010 16:48: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)
Hello,

Here are some additional notes about argument functions.
Functions can be defined in a preferable way (IMHO)
Fun(a,b,f(2))←a+b+f(a,Cool/2
Or with dummy arguments. Dummy arguments can be even with the same names. Here are some examples:
Fun_2(a,b,f(a_,a_))←a+b+f(a,Cool/2
Fun_3(a,b,f(_1,_2))←a+b+f(a,Cool/2
Fun_4(a,b,f(_,_))←a+b+f(a,Cool/2
User can choose the most convenient way of defining these functions.
When calling, it is important to have in mind that (already mentioned)
1. argument functions must have variables as arguments
2. names from the argument list or previously defined variables are not allowed.
3. names should be different, contrary to the definition (SMath will not report an error here - It is allowed but pay attention on the result!)
Therefore, user can have its own naming conventions for these argument names - some unusul names used only in these cases. Here is the example by using underscore:
Fun_1(x,y,ff(_a,_Cool)=15
Fun_2(x,y,ff(_a,_Cool)=15
Fun_3(x,y,ff(a_,b_))=15
And my favorite one at the moment:
Fun_4(x,y,ff(_1,_2))=15

None of the variables _a, _b, a_, b_, _1, _2 were not previously defined

Regards,
Radovan

Edited by user 08 August 2010 22:22:48(UTC)  | Reason: Not specified

When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
Offline mikekaganski  
#23 Posted : 22 April 2014 03:49:48(UTC)
mikekaganski


Rank: Advanced Member

Groups: Registered
Joined: 17/01/2013(UTC)
Posts: 296
Man
Russian Federation
Location: Khabarovsk, Russia

Was thanked: 151 time(s) in 107 post(s)
Hi,

I can't manage to use functions as arguments in following scenario:

f(g(1);x):=g(x)
g(x):=eval(x+x)
f(g(_);2)=Error: "_ Not Defined".

eval here disables using function as argument (yet another eval() deficiency! Sad ). This is highly unfortunate, as my functions have to use evals to avoid overflow.

Another problem:

f(g(2);x;y):=g(x;y)
g(x;y):=x^y
f(g(_;_);1;2)=4
f(g(_1;_2);1;2)=1

(_, _1 and _2 are all uninitialized)

i.e. dummy argument names to function as argument affect the function expansion, in this specific case making it use y for both x and y! Of course, using different names makes things OK, but this is still a bug, because in the function definition the call is g(x,y), not g(y,y). I believe that the names of dummy arguments must be completely ignored (only tested for not being initialized), and repeating them should make no difference.

Edit: second problem is discussed in clause 3 of previous post #22. Still, I suppose that it should be fixed.

Edited by user 22 April 2014 05:35:08(UTC)  | Reason: Not specified

Best regards,
Mike Kaganski
thanks 1 user thanked mikekaganski for this useful post.
on 22/04/2014(UTC)
Offline omorr  
#24 Posted : 22 April 2014 10:30:29(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 mikagenski for this post,

There is one thing that makes me sad sometimes Sad . It is the date on some posts. For instance, when there is "Posted: 6 hours ago" following "Posted: 4 years ago". On the other hand, let's be positive. It is good that this still actually exists and I hope that we will see one day "Posted: 20 years ago". We could then remind ourselves how clever we were long time ago Good .

Regards,
Radovan

Edited by user 22 April 2014 10:32:51(UTC)  | Reason: Not specified

When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
Offline mkraska  
#25 Posted : 22 April 2014 11:49:34(UTC)
mkraska


Rank: Advanced Member

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

Was thanked: 1124 time(s) in 721 post(s)
Originally Posted by: mikekaganski Go to Quoted Post
Hi,

I can't manage to use functions as arguments in following scenario:

f(g(1);x):=g(x)
g(x):=eval(x+x)
f(g(_);2)=Error: "_ Not Defined".

eval here disables using function as argument (yet another eval() deficiency! Sad ). This is highly unfortunate, as my functions have to use evals to avoid overflow.

If eval() would return itself without evaluation if the numeric evaluation fails, this particular problem should be solved. Filed as proposal SS-123.
Martin Kraska

Pre-configured portable distribution of SMath Studio: https://smath.com/wiki/SMath_with_Plugins.ashx
thanks 1 user thanked mkraska for this useful post.
on 22/04/2014(UTC)
Users browsing this topic
2 Pages<12
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.