ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 15 Jun 2018 04:38:16 +0200How to access variables from libsingular?https://ask.sagemath.org/question/42413/how-to-access-variables-from-libsingular/I have some Sage code that works using the expect interface, and I'm trying to port it to `libsingular`.
The Singular function in question (`absFactorize`) returns a ring with an associated variable. In the expect interface, we `setring` the returned ring, then evaluate the variable name, i.e:
R = norm_f._singular_().absFactorize()
singular.setring(R)
L = singular('absolute_factors')
Anybody know how to do this with `libsingular`?Wed, 23 May 2018 23:47:38 +0200https://ask.sagemath.org/question/42413/how-to-access-variables-from-libsingular/Answer by nbruin for <p>I have some Sage code that works using the expect interface, and I'm trying to port it to <code>libsingular</code>.</p>
<p>The Singular function in question (<code>absFactorize</code>) returns a ring with an associated variable. In the expect interface, we <code>setring</code> the returned ring, then evaluate the variable name, i.e:</p>
<pre><code> R = norm_f._singular_().absFactorize()
singular.setring(R)
L = singular('absolute_factors')
</code></pre>
<p>Anybody know how to do this with <code>libsingular</code>?</p>
https://ask.sagemath.org/question/42413/how-to-access-variables-from-libsingular/?answer=42418#post-id-42418In order to get the routine defined you'd do something like
R.<x,y>=QQ[]
f=x^2-y^2
sage.libs.singular.function.lib("absfact.lib")
absFactorize=sage.libs.singular.function.singular_function("absFactorize")
which then would allow you to do something like
W=absFactorize(f)
Problem is: that gives back a nearly useless "RingWrap" object.
The libsingular function call interface seems to go out of its way to set the ring on every invocation (otherwise the state of the library interface would be difficult to manage). So improving RingWrap so that a "setring(W)" works likely wouldn't do something useful. Would you be able to write some singular code that wraps absFactorize and returns the data you're after in a more usable form? Then you can read in THAT function and use that instead. Looking at the design of libSingular, that seems to me the easiest solution at the moment. But I might be overlooking something.
**EDIT** It's tricky, though: the Singular language interpreter seems to have great trouble handling polynomials in rings that are not the current ring. Furthermore, you'll have to construct a ring in sage to serve as a parent for conversions of the relevant polynomials. I suspect it might require some direct interfacing with libsingular on cython/C level. Clearly, Singular can represent the relevant objects, but I think the current design of AbsFactorize (to wrap the answer in a ring) is guided by limitations of the language.Thu, 24 May 2018 05:47:51 +0200https://ask.sagemath.org/question/42413/how-to-access-variables-from-libsingular/?answer=42418#post-id-42418Comment by BrentBaccala for <p>In order to get the routine defined you'd do something like</p>
<pre><code>R.<x,y>=QQ[]
f=x^2-y^2
sage.libs.singular.function.lib("absfact.lib")
absFactorize=sage.libs.singular.function.singular_function("absFactorize")
</code></pre>
<p>which then would allow you to do something like</p>
<pre><code>W=absFactorize(f)
</code></pre>
<p>Problem is: that gives back a nearly useless "RingWrap" object.</p>
<p>The libsingular function call interface seems to go out of its way to set the ring on every invocation (otherwise the state of the library interface would be difficult to manage). So improving RingWrap so that a "setring(W)" works likely wouldn't do something useful. Would you be able to write some singular code that wraps absFactorize and returns the data you're after in a more usable form? Then you can read in THAT function and use that instead. Looking at the design of libSingular, that seems to me the easiest solution at the moment. But I might be overlooking something.</p>
<p><strong>EDIT</strong> It's tricky, though: the Singular language interpreter seems to have great trouble handling polynomials in rings that are not the current ring. Furthermore, you'll have to construct a ring in sage to serve as a parent for conversions of the relevant polynomials. I suspect it might require some direct interfacing with libsingular on cython/C level. Clearly, Singular can represent the relevant objects, but I think the current design of AbsFactorize (to wrap the answer in a ring) is guided by limitations of the language.</p>
https://ask.sagemath.org/question/42413/how-to-access-variables-from-libsingular/?comment=42436#post-id-42436I was hoping for something else, but your suggestion (write a wrapper function) might be the most practical solution.Fri, 25 May 2018 21:44:05 +0200https://ask.sagemath.org/question/42413/how-to-access-variables-from-libsingular/?comment=42436#post-id-42436Comment by BrentBaccala for <p>In order to get the routine defined you'd do something like</p>
<pre><code>R.<x,y>=QQ[]
f=x^2-y^2
sage.libs.singular.function.lib("absfact.lib")
absFactorize=sage.libs.singular.function.singular_function("absFactorize")
</code></pre>
<p>which then would allow you to do something like</p>
<pre><code>W=absFactorize(f)
</code></pre>
<p>Problem is: that gives back a nearly useless "RingWrap" object.</p>
<p>The libsingular function call interface seems to go out of its way to set the ring on every invocation (otherwise the state of the library interface would be difficult to manage). So improving RingWrap so that a "setring(W)" works likely wouldn't do something useful. Would you be able to write some singular code that wraps absFactorize and returns the data you're after in a more usable form? Then you can read in THAT function and use that instead. Looking at the design of libSingular, that seems to me the easiest solution at the moment. But I might be overlooking something.</p>
<p><strong>EDIT</strong> It's tricky, though: the Singular language interpreter seems to have great trouble handling polynomials in rings that are not the current ring. Furthermore, you'll have to construct a ring in sage to serve as a parent for conversions of the relevant polynomials. I suspect it might require some direct interfacing with libsingular on cython/C level. Clearly, Singular can represent the relevant objects, but I think the current design of AbsFactorize (to wrap the answer in a ring) is guided by limitations of the language.</p>
https://ask.sagemath.org/question/42413/how-to-access-variables-from-libsingular/?comment=42606#post-id-42606I wasn't able to get it working using only the Singular language. libsingular prohibits subroutines changing the basering, and I couldn't figure how to access the variable without changing the basering. @nbruin seems to be right - something in cython/C is probably required.Fri, 15 Jun 2018 04:38:16 +0200https://ask.sagemath.org/question/42413/how-to-access-variables-from-libsingular/?comment=42606#post-id-42606