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

using references to rings and preimage computing
https://www.singular.uni-kl.de/forum/viewtopic.php?f=10&t=2265
Page 1 of 1

Author:  jack [ Thu Jun 27, 2013 11:44 am ]
Post subject:  using references to rings and preimage computing

What is the best way to fix the following failing preimage computation,
define in 'computePreimage' a local map lphi?


Code:
system("reference");
  system("shared");


proc computeImage( parentRingRef, childRingRef,  srcIdealName, dstIdealName )
{
    def refRing = basering;

    def localChildRing = link(childRingRef);
    def localParentRing = link(parentRingRef);
    setring localChildRing;

    string mapCmd = "def " + dstIdealName + " = phi("+srcIdealName+");";
    execute(mapCmd);   

    string exportCmd = "export( "+dstIdealName+");";
    execute( exportCmd );   

    setring refRing;
    kill localChildRing;
    kill localParentRing;
    return (0);
}


proc computePreimage (parentRingRef,childRingRef, srcIdealName, dstIdealName)
{
    def localParentRing = link  (parentRingRef);
    def localChildRing = link  (childRingRef);
    def refRing = basering;

    setring localParentRing;
   
    string mapCmd = "def " + dstIdealName + " =  preimage( localChildRing, phi, " + srcIdealName + ");";       
    execute( mapCmd );   

    string exportCmd = "export( " + dstIdealName + " );";
    execute( exportCmd );   


    setring refRing;
    kill localChildRing;
    kill localParentRing;
    return ( 0 );
}



proc testPreimage1()
{
    ring parentRing = integer,(x,y,z),dp;
    reference parentRingRef = parentRing;
   
    ideal I = x^3+y;

    ring childRing = integer,(X(1),X(2)),dp;
    reference childRingRef = childRing;

    setring    childRing;

    ideal cX = X(1)^3+X(2);

    ideal mapIdeal = X(1),X(2);
    export(mapIdeal);
    map phi = parentRing, mapIdeal;
    export(phi);
 

    computeImage(parentRingRef, childRingRef, "I", "mappedI");

    computePreimage(parentRingRef, childRingRef, "cX", "pX");
}


// fails:
testPreimage1();


Author:  hannes [ Fri Jun 28, 2013 3:22 am ]
Post subject:  Re: using references to rings and preimage computing

The preimage ring of phi (parentRing) is a local variable of testPreimage1
and therefore not available in computeImage.

If you want to fix it, export parentRing.

Another point: assignment of rings is always via reference, no need to
use system(reference) or system(shared) for that.

Author:  jack [ Mon Jul 01, 2013 12:43 am ]
Post subject:  Re: using references to rings and preimage computing

hannes wrote:
[...] Another point: assignment of rings is always via reference, no need to
use system(reference) or system(shared) for that.


Are you sure, that there is no need for ring references?

It was for me impossible to set ring attributes without using references:

Code:
system("reference");

proc setAttrib( rng, attrubuteName, attributeVal)
{
   attrib( rng, attrubuteName, attributeVal);
}

proc setAttribOfRef( pRngRef, attrubuteName, attributeVal)
{
   attrib( pRngRef ,attrubuteName, attributeVal);
}


proc minimalExample()
{
   string attributeName = "name";
   string attributeVal  = "it works!";

   ring parentRing = integer,(x,y,z),dp;
   
   setAttrib( parentRing,attributeName,attributeVal);
   if ( attrib( parentRing, attributeName )<> attributeVal ) 
   { print("setting attrubute by passing ordinary copy failed"); }
   else   { print("setting attrubute by passing ordinary copy succeeded"); }

   reference rngRef =  parentRing;

   setAttribOfRef(  rngRef,attributeName,attributeVal);
   if ( attrib( parentRing, attributeName )<> attributeVal ) 
   { print("setting attrubute by passing reference failed"); }
   else  { print("setting attrubute by passing reference succeeded !"); }
}


minimalExample();

Author:  jack [ Mon Jul 01, 2013 1:49 pm ]
Post subject:  Re: using references to rings and preimage computing

hannes wrote:
If you want to fix it, export parentRing.

To avoid usage of global variables,
my solution was to define a local map object in the procedure instead
utilizing the 'mapIdeal'.

What amount of overhead is produced by creating a map object?
Are the entries of 'mapIdeal' copied each time?

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