using Macaulay2's toString to define a function in Sage

46 views
Skip to first unread message

saad khalid

unread,
Jul 11, 2016, 10:27:38 PM7/11/16
to sage-support
Hey everyone:

So, it turns out that Macaulay2 has an inbuilt function to convert it's ascii output of exponents into a normal string. It can be seen at the end this example:

reset()
macaulay2
.eval("""
K = toField(QQ[zet]/(zet^6 + zet^3 + 1))
A=matrix{{zet^1,0},{0,zet^8}}
needsPackage "
InvariantRing"
G=generateGroup({A},K)
P = molienSeries G
X = toString P
 """
)


sage
:
PolynomialRing

| zet 0            |
| 0   -zet^5-zet^2 |

       
2       2
Matrix K  <--- K

InvariantRing

Package

{| 1 0 |, | zet 0            |, | zet^5 0     |, | -zet^3-1 0     |, | -zet^4-zet 0     |, | zet^3 0        |, | zet^4 0     |, | -zet^5-zet^2 0   |, | zet^2 0          |}
 
| 0 1 |  | 0   -zet^5-zet^2 |  | 0     zet^4 |  | 0        zet^3 |  | 0          zet^2 |  | 0     -zet^3-1 |  | 0     zet^5 |  | 0            zet |  | 0     -zet^4-zet |

List

         
2    3    4    5    6    7    8
1 - T + T  - T  + T  - T  + T  - T  + T
----------------------------------------
         
3    6        2          2
   
(1 + T  + T )(1 - T) (1 + T + T )

Expression of class Divide

(1-T+T^2-T^3+T^4-T^5+T^6-T^7+T^8)/((1+T^3+T^6)*(1-T)^2*(1+T+T^2))

So, I want to be able to take that string output and define a Sage function from it, and then ideally be able to take its Taylor series. here is what I'm trying:

var('T')
str
(T) = macaulay2('X')
str
(1)


sage:T
sage:(1-T+T^2-T^3+T^4-T^5+T^6-T^7+T^8)/((1+T^3+T^6)*(1-T)^2*(1+T+T^2))

For some reason, it won't recognize T as a variable and won't let me make a function out of it. Would anyone have any tricks on making this work?

Dima Pasechnik

unread,
Jul 12, 2016, 4:46:08 AM7/12/16
to sage-support
this line does not look right to me.

 

str
(1)


sage:T
sage:(1-T+T^2-T^3+T^4-T^5+T^6-T^7+T^8)/((1+T^3+T^6)*(1-T)^2*(1+T+T^2))
this seems to say that T is no longer a variable, but an expression.
What you seem to have done is to define an expression in SR (i.e. in Symbolic Ring), but in a variable that is no longer an SR variable.
 

For some reason, it won't recognize T as a variable and won't let me make a function out of it. Would anyone have any tricks on making this work?


I thought I already told you a trick - convert things into Sage polynomials first, and then convert them into SR elements. E.g.

sage: R.<t,u>=QQ[]
sage: p=t^2+1+7*u     # you can also get such a polynomial from M2
sage: type(p)
<type 'sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular'>
sage: type(SR(p))
<type 'sage.symbolic.expression.Expression'>
sage: sin(SR(p)).diff(t)
2*t*cos(t^2 + 7*u + 1)
sage: sin(SR(p)).diff(u)
7*cos(t^2 + 7*u + 1)

Hope this helps,
Dima

 
Reply all
Reply to author
Forward
0 new messages