On Sep 24, 6:56 pm, kcrisman <kcris...@gmail.com> wrote: > If I make a polynomial ring using > > sage: b = PolynomialRing(ZZ, 'x') > > I get some odd behavior. Namely, > > sage: bool(b(x)==x) > True
I personally find this slightly worrisome, but this was a design decision (equality respects automatic coercions) > sage: b(x) > x > sage: type(b(x)) > <something about element of the ring> > sage: type(x) > <symbolic expression> > > This isn't really that odd, but still I don't know whether it is good > that one can still use x as a symbolic variable. This is the only possibility, because the "var('x')" command executed by default at startup did the assignment x = SR('x') and you haven't bound x to any other object. Once you execute x = b.0 [ or one of its implicit forms like b.<x>=PolynomialRing(ZZ,'x')] then x is no longer referencing the "symbolic expression x", but the "univariate polynomial x" instead. > sage: a = FractionField(PolynomialRing(ZZ, 'x')) > sage: a(1/x) > <weird error that seems to imply it has not coerced x to the > polynomial ring> sage: Xsym = var('x') sage: P=PolynomialRing(ZZ,'x') sage: Xpoly = P.gen(0) sage: FP=FractionField(P) sage: Xratfunc = FP.gen(0) sage: bool(1/Xratfunc == 1/Xsym) True sage: FP(1/Xsym) TypeError: denominator must be a unit It seems things are mainly going in the other direction: sage: cm = sage.structure.element.get_coercion_model() sage: cm.explain(parent(Xsym),parent(Xratfunc),operator.eq) Coercion on right operand via Conversion via _symbolic_ method map: From: Fraction Field of Univariate Polynomial Ring in x over Integer Ring To: Symbolic Ring Arithmetic performed after coercions. Result lives in Symbolic Ring Symbolic Ring which is correct: A rational function with integer coordinates can definitely be coerced into the symbolic ring, but in the other direction, one can only hope for a conversion map that is partially defined: sage: FP(1/SR('y')) TypeError: y is not a variable of Univariate Polynomial Ring in x over Integer Ring It looks to me as if FP(1/Xsym) is trying to convert via P: sage: P(1/Xsym) TypeError: denominator must be a unit Given that the error returned for FP(1/Xsym) is nonsensical, it's reasonable to call it a bug. The obvious way to fix it is by handling conversions from SR a little more intelligently. Beware though, because the parents could be really nasty: sage: F=PolynomialRing(FractionField(PolynomialRing(FractionField(PolynomialRing(ZZ,'x')),'y')),'z') sage: F(SR( '1/x+1/y*x')) sage: F(1/Xsym) which, surprisingly, works already!! So yes, it's a bug and it's probably something simple that's missing on the optimized univariate polynomial ring over the integers. -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org