Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Procedure With External Parameters
PostPosted: Tue Aug 28, 2012 3:19 pm 

Joined: Mon Aug 27, 2012 7:45 pm
Posts: 2
How can one define a procedure which may be called with parameters not in the current ring, such as "imap(R,f)", where the polynomial "f" belongs to the ring "R"?


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Procedure With External Parameters
PostPosted: Sat Sep 01, 2012 3:03 pm 

Joined: Thu Mar 04, 2010 1:29 pm
Posts: 14
One possibility is to define a procedure which takes the ring R as a parameter. Objects inside this ring can then be accessed by their names:

Code:
proc p1(def R, string nameofpoly)
{
    setring(R);
    execute(nameofpoly);
}

ring R = 0, (x,y,z), dp;
poly f = x+y+z;
ring S = 0, x, dp;
p1(R, "f");
x+y+z


Note that
Code:
proc p1(ring R, ...)

does not work, see http://www.singular.uni-kl.de/Manual/la ... .htm#SEC81.

Another possibility is to use user defined types ("newstructs"), see http://www.singular.uni-kl.de/Manual/la ... htm#SEC216.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Procedure With External Parameters
PostPosted: Fri Sep 07, 2012 3:56 pm 

Joined: Wed Mar 03, 2010 5:08 pm
Posts: 108
Location: Germany, Münster
With execute the polynomial will just be displayed but you can't work with it.
Even an assignment afterwards like poly g = _; is not possible.

To have access, you must enclose the string (variable) nameofpoly into
the backticks ` ` . These are the delimiter for name substitution

See Special characters:
http://www.singular.uni-kl.de/Manual/la ... .htm#SEC63

Modified solution:
Code:
> ring R = 0, (x,y,z), dp;
> poly f = x+y+z;
> string s = "f";
> `s`;
x+y+z

> proc p1mod(def R, string nameofpoly)
{
    setring(R);
    poly g = `nameofpoly`;
    g = g+1;
    g;
}

> ring S = 0, x, dp;
> p1mod(R, "f");
x+y+z+1


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

It is currently Fri May 13, 2022 11:05 am
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group