1 | initial version |
There is no mathematical difference, but an algorithmic one: in the second case, a polynomial is represented as a list of its coefficients up to its degree, in the first case, it only stores the nonzero coefficient (but in a different data strutcure to also store the corresponding degrees, like a dictionary). The size of the object and the algorithms to deal with them are different.
Let us construct some polynomials in both parents and look and save them:
sage: R.<z> = PolynomialRing(ZZ, sparse=False)
sage: save(z^1000,'/tmp/nosparse_atom.sobj')
sage: save(sum(z^k for k in range(1001)),'/tmp/nosparse_sum.sobj')
sage: R.<z> = PolynomialRing(ZZ, sparse=True)
sage: save(z^1000,'/tmp/sparse_atom.sobj')
sage: save(sum(z^k for k in range(1001)),'/tmp/sparse_sum.sobj')
then, let us do ls -l /tmp
in a terminal and see their respective size:
nosparse_atom.sobj 2082
nosparse_sum.sobj 2081
sparse_atom.sobj 590
sparse_sum.sobj 4009
As you can see, in the nonsparse case, both polynomials have about the same size in memory (storing the coefficient 1 is the same as storing the coefficient 0). In the sparse case, a lot of memory is saved in storing only the pair (1000,1)
, while for the sum, the object is about twice the size since both degrees and coefficients have tobe stored.
2 | No.2 Revision |
There is no mathematical difference, but an algorithmic one: in the second nonsparse case, a polynomial is represented as a list of its coefficients up to its degree, in the first sparse case, it only stores the nonzero coefficient (but in a different data strutcure to also store the corresponding degrees, like a dictionary). dictionary, or a list of tuples). The size of the object corresponding objects and the algorithms to deal with them are different.
Let us construct some polynomials in both parents and look and save them:
sage: R.<z> = PolynomialRing(ZZ, sparse=False)
sage: save(z^1000,'/tmp/nosparse_atom.sobj')
sage: save(sum(z^k for k in range(1001)),'/tmp/nosparse_sum.sobj')
sage: R.<z> = PolynomialRing(ZZ, sparse=True)
sage: save(z^1000,'/tmp/sparse_atom.sobj')
sage: save(sum(z^k for k in range(1001)),'/tmp/sparse_sum.sobj')
then, let us do ls -l /tmp
in a terminal and see their respective size:
nosparse_atom.sobj 2082
nosparse_sum.sobj 2081
sparse_atom.sobj 590
sparse_sum.sobj 4009
As you can see, in the nonsparse case, both polynomials have about the same size in memory (storing the coefficient 1 is the same as storing the coefficient 0). In the sparse case, a lot of memory is saved in storing only the pair (1000,1)
, while for the sum, the object is about twice the size since both degrees and coefficients have tobe stored.