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.Thu, 02 Apr 2020 14:32:40 +0200Passing Sage functions to Singularhttps://ask.sagemath.org/question/50462/passing-sage-functions-to-singular/Hello Everyone,
given a polynomial $f\colon \mathbb{C}^2 \to \mathbb{C}$ in two complex variables $x, y$ together with a singular isolated point $(0, 0)$ of $f$, I try to extract information about the set of points $(x,y)\in \mathbb{C}^2: f(x,y)=0$ that intersect a small sphere ${S_\epsilon}^3 (z)$ centered at the origin. In order to obtain points $(x,y)$ satisfying both conditions, I wanted to split my two complex variables $(x,y)$ in their real and imaginary part to obtain a polynomial $f\colon \mathbb{R}^4 \to \mathbb{R}^2$ and to easily write the second condition in terms of $$ x_1^2 + x_2 ^2 +y_1^2 + y_2 ^2 - \epsilon^2 =0, \qquad x=x_1 + i~x_2, ~~y=y_1 + i~y_2.$$
I know that the solution is homeomorphic to $S^1 \cup S^1$, that's why I want to pass $f$ splitted in real and imaginary part as functions of $(x_1, x_2, y_1, y_2)$ to Singular together with the equation above, to get the two components of the solution. Everything works perfectly so far (giving the equations to Singular directly), except that I can't manage to pass the functions from Sage to singular (via the built-in Interface).
I tried something like:
C.<x, y> = PolynomialRing(CC)
f = x^2 +y^2
f1 = real_part(f)
f2 = imag_part(f); f2
# The output for f2 is:
# 2.00000000000000*imag_part(x)*real_part(x) + 2.00000000000000*imag_part(y)*real_part(y)
I know how to define new functions in Singular via
R = singular.ring(0, '(x_1,x_2,y_1,y_2)', 'lp')
g = singular.new('2*x_1*x_2 + 2*y_1*y_2')
but how can I pass f1 and f2 to Singular and tell Singular to treat them as functions of $(x_1, x_2, y_1, y_2)$?
Thanks you very much!Thu, 02 Apr 2020 12:26:07 +0200https://ask.sagemath.org/question/50462/passing-sage-functions-to-singular/Answer by rburing for <p>Hello Everyone,</p>
<p>given a polynomial $f\colon \mathbb{C}^2 \to \mathbb{C}$ in two complex variables $x, y$ together with a singular isolated point $(0, 0)$ of $f$, I try to extract information about the set of points $(x,y)\in \mathbb{C}^2: f(x,y)=0$ that intersect a small sphere ${S_\epsilon}^3 (z)$ centered at the origin. In order to obtain points $(x,y)$ satisfying both conditions, I wanted to split my two complex variables $(x,y)$ in their real and imaginary part to obtain a polynomial $f\colon \mathbb{R}^4 \to \mathbb{R}^2$ and to easily write the second condition in terms of $$ x_1^2 + x_2 ^2 +y_1^2 + y_2 ^2 - \epsilon^2 =0, \qquad x=x_1 + i~x_2, ~~y=y_1 + i~y_2.$$</p>
<p>I know that the solution is homeomorphic to $S^1 \cup S^1$, that's why I want to pass $f$ splitted in real and imaginary part as functions of $(x_1, x_2, y_1, y_2)$ to Singular together with the equation above, to get the two components of the solution. Everything works perfectly so far (giving the equations to Singular directly), except that I can't manage to pass the functions from Sage to singular (via the built-in Interface).</p>
<p>I tried something like:</p>
<pre><code>C.<x, y> = PolynomialRing(CC)
f = x^2 +y^2
f1 = real_part(f)
f2 = imag_part(f); f2
# The output for f2 is:
# 2.00000000000000*imag_part(x)*real_part(x) + 2.00000000000000*imag_part(y)*real_part(y)
</code></pre>
<p>I know how to define new functions in Singular via</p>
<pre><code>R = singular.ring(0, '(x_1,x_2,y_1,y_2)', 'lp')
g = singular.new('2*x_1*x_2 + 2*y_1*y_2')
</code></pre>
<p>but how can I pass f1 and f2 to Singular and tell Singular to treat them as functions of $(x_1, x_2, y_1, y_2)$?</p>
<p>Thanks you very much!</p>
https://ask.sagemath.org/question/50462/passing-sage-functions-to-singular/?answer=50465#post-id-50465You could do something like this:
C.<x, y> = PolynomialRing(QQ)
f = x^2 + y^2
S.<x_1,x_2,y_1,y_2,i> = PolynomialRing(QQ)
F = f.subs({x: x_1 + i*x_2, y: y_1 + i*y_2}).reduce([i^2+1])
f1, f2 = F.polynomial(i).coefficients()
R = singular.ring(0,'(x_1,x_2,y_1,y_2)', 'lp')
g1 = singular.new(str(f1))
g2 = singular.new(str(f2))
g1, g2
Output:
(x_1^2-x_2^2+y_1^2-y_2^2, 2*x_1*x_2+2*y_1*y_2)
You can also use `R.fetch(g)` to force Singular polynomials `g` into your particular Singular ring `R`.Thu, 02 Apr 2020 14:16:03 +0200https://ask.sagemath.org/question/50462/passing-sage-functions-to-singular/?answer=50465#post-id-50465Comment by PaulEbert for <p>You could do something like this:</p>
<pre><code>C.<x, y> = PolynomialRing(QQ)
f = x^2 + y^2
S.<x_1,x_2,y_1,y_2,i> = PolynomialRing(QQ)
F = f.subs({x: x_1 + i*x_2, y: y_1 + i*y_2}).reduce([i^2+1])
f1, f2 = F.polynomial(i).coefficients()
R = singular.ring(0,'(x_1,x_2,y_1,y_2)', 'lp')
g1 = singular.new(str(f1))
g2 = singular.new(str(f2))
g1, g2
</code></pre>
<p>Output:</p>
<pre><code>(x_1^2-x_2^2+y_1^2-y_2^2, 2*x_1*x_2+2*y_1*y_2)
</code></pre>
<p>You can also use <code>R.fetch(g)</code> to force Singular polynomials <code>g</code> into your particular Singular ring <code>R</code>.</p>
https://ask.sagemath.org/question/50462/passing-sage-functions-to-singular/?comment=50466#post-id-50466Thanks for you fast response, your solution works perfectly.Thu, 02 Apr 2020 14:32:40 +0200https://ask.sagemath.org/question/50462/passing-sage-functions-to-singular/?comment=50466#post-id-50466