On Feb 14, 7:27 am, Ben Hutz <[email protected]> wrote:
> I seem to be getting a weird result when I use .subs over QQbar:
>
> R.<x,y,c>=PolynomialRing(QQbar,3)
> Y=(x^4*y + 2*c*x^2*y^3 - x*y^4 + (c^2 + c)*y^5)/(x^2*y - x*y^2 +c*y^3)
> fm=[x^2 + c*y^2, y^2]
> W1=Y.subs({x:fm[0],y:fm[1]})

The rest of the results are as they should be (for as far as I can
check). The result of this one is the problematic one: W1==Y; no
substitution is done. The reason for this is:

sage: gen = W1.parent().gen(0)
sage: (x,gen)
(x, x)
sage: (x.parent(),gen.parent())
(Multivariate Polynomial Ring in x, y, c over Algebraic Field,
 Fraction Field of Multivariate Polynomial Ring in x, y, c over
Algebraic Field)
sage: x == gen
True
sage: x in {x: 1}
True
sage: gen in {x: 1}
False
sage: hash(x),hash(gen)
(5589993095651593830, -9103327893471890662)

The last two lines show the problem: You are labelling your
substitutions with polynomial ring generators instead of fraction
field generators, so the system essentially finds these aren't
occurring. Relative to Python's rules, "equality" gets abused in sage
(it's not transitive for one matter) and makes it impossible to
provide useful hash values without breaking "equality implies equal
hash values)

If you do

sage: Y.subs(x=fm[0],y=fm[0])

no problem arises: The keywords now are just python parameters, so the
only way to do the lookup is via string comparisons.

Alternatively, and this will be faster since subs is just a wrapper
around call anyway,

sage: Y(fm + [c])

which avoids complicated lookups altogether, because what belong where
is encoded by order.

I don't think it's feasible to fix the hash values.

An alternative would be to process the keys of dictionary input to
strings and compare them with string reps of the generators, so that
Y.subs(fm) leads to the same code as the explicit keyword version. I
think that's questionable: You are feeding the system a different kind
of x than is natural for the object (where would we stop with x. If
you substitute into a polynomial using generators of the fraction
field, should the result try to lie in the polynomial ring or
immediately go for the fraction field?)

Just use call.

I'd expect this problem is not unique to QQbar.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-devel?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to