Hi, On Mon, Apr 19, 2010 at 08:28:21AM -0700, Ben Goodrich wrote: > Hi, > > Okay, I got the domain thing figured out, but now I am running into a > separate problem when the polynomial in sdp form is inside of a > matrix. > > All this is fine: > > from sympy.polys.monomialtools import monomial_lex_key as O_lex > from sympy.polys.groebnertools import * > from sympy.polys.polytools import basic_from_dict > gens = symbols('xyz') > f = x**3 + 2 * y**2 - z > F = Poly(f, *gens)
The following line needs a few words of comment. > FF = sdp_from_dict(F.as_dict(), O_lex) F.as_dict() returns { M_i: c_i } representation where M_i are tuples with exponents of type int and c_i are coefficients of type Integer. > Poly(dict(FF), *gens) == F # True If you create a Poly of FF as above, then there is no problem. If you would specify the domain via domain='ZZ', then you can run into trouble because ZZ.dtype won't match c_i type (e.g. it might be mpz v.s. Integer). Secondly, if you will use FF for computations then F.as_dict() shouldn't be used. Probably I used as_dict() improperly earlier in this thread. So, F.as_dict() should be replaced with F.rep.to_dict() which return a dict as as_dict() does, but c_i type will match ZZ.dtype. > > But not this: > > M = Matrix(1, 1, [FF]) > Poly(dict(M[0,0]), *gens) == F # False > > because the left-hand side becomes the zero polynomial for some reason > > In [45]: Poly(dict(M[0,0]), *gens) > Out[45]: Poly(0, x, y, z, domain='ZZ') > > It appears to be something related to the coercion to a dictionary > > M[0,0] == FF # True > dict(M[0,0]) == dict(FF) # False > > even though they look identical > > In [50]: dict(M[0,0]) > Out[50]: {(0, 0, 1): -1, (0, 2, 0): 2, (3, 0, 0): 1} > > In [51]: dict(FF) > Out[51]: {(0, 0, 1): -1, (0, 2, 0): 2, (3, 0, 0): 1} > > Any ideas? > They look identical, but they're not. As you use F.as_dict(), then in both cases c_i are of type Integer. However, keys of _50 and _51 are different. In _50 M_i are tuples of Integer instances and in _51 they are tuples of ints. When you created a Matrix of FF then FF got sympified and all ints were converted to Integers. Poly, however, expects M_i to have int exponents. To solve this problem you can replace dict(M[0,0]) with: dict([ (map(int, monom), coeff) for monom, coeff in M[0,0] ]) > Thanks, > Ben > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To post to this group, send email to sy...@googlegroups.com. > To unsubscribe from this group, send email to > sympy+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/sympy?hl=en. > -- Mateusz
signature.asc
Description: This is a digitally signed message part