Singular
https://www.singular.uni-kl.de/forum/

Procedure With External Parameters
https://www.singular.uni-kl.de/forum/viewtopic.php?f=10&t=2128
Page 1 of 1

Author:  Guillermo PeƱafort [ Tue Aug 28, 2012 3:19 pm ]
Post subject:  Procedure With External Parameters

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"?

Author:  steenpass [ Sat Sep 01, 2012 3:03 pm ]
Post subject:  Re: Procedure With External Parameters

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.

Author:  gorzel [ Fri Sep 07, 2012 3:56 pm ]
Post subject:  Re: Procedure With External Parameters

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

Page 1 of 1 All times are UTC + 1 hour [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/