next | previous | forward | backward | up | top | index | toc | Macaulay2 web site
Macaulay2Doc > The Macaulay2 language > saving polynomials and matrices in files

saving polynomials and matrices in files

Use the function toString to convert polynomials, matrices, and other mathematical objects to a linear format that can be saved in a file.
i1 : R = QQ[x..z]

o1 = R

o1 : PolynomialRing
i2 : p = (x-y-1)^3

      3     2        2    3     2            2
o2 = x  - 3x y + 3x*y  - y  - 3x  + 6x*y - 3y  + 3x - 3y - 1

o2 : R
i3 : m = matrix {{x^2, x^2-y^2, x*y*z^7 }}

o3 = | x2 x2-y2 xyz7 |

             1       3
o3 : Matrix R  <--- R
i4 : M = image m

o4 = image | x2 x2-y2 xyz7 |

                             1
o4 : R-module, submodule of R
i5 : f = temporaryFileName()

o5 = /tmp/M2-24125-0/0
i6 : f << toString (p,m,M) << close

o6 = /tmp/M2-24125-0/0

o6 : File
i7 : get f

o7 = (x^3-3*x^2*y+3*x*y^2-y^3-3*x^2+6*x*y-3*y^2+3*x-3*y-1,matrix {{x^2,
     x^2-y^2, x*y*z^7}},image matrix {{x^2, x^2-y^2, x*y*z^7}})
i8 : (p',m',M') = value get f

       3     2        2    3     2            2
o8 = (x  - 3x y + 3x*y  - y  - 3x  + 6x*y - 3y  + 3x - 3y - 1, | x2 x2-y2
     ------------------------------------------------------------------------
     xyz7 |, image | x2 x2-y2 xyz7 |)

o8 : Sequence
i9 : p == p'

o9 = true
i10 : m == m'

o10 = true
i11 : M == M'

o11 = true
i12 : removeFile f