On Fri, Sep 24, 2010 at 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
> 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.  Probably this was a
> design decision.

There is the distinction between x the Python variable and x the
symbol (aka symbolic variable). For example, in the code below x and y
both "store" the symbol x.

sage: y = x
sage: y
x

x just happens to start out as a symbolic variable with the same name
as the Python variable. In general, we try to avoid overwriting the
namespace, so when you do

sage: x = 3
sage: PolynomialRing(ZZ, 'x')
Univariate Polynomial Ring in x over Integer Ring
sage: x
3

you don't have any surprises. You can change this with inject_on()

sage: inject_on()
Redefining: FiniteField Frac FractionField FreeMonoid GF
LaurentSeriesRing NumberField PolynomialRing quo quotient
sage: PolynomialRing(ZZ, 'x')
Defining x
Univariate Polynomial Ring in x over Integer Ring
sage: x
x
sage: type(x)
<type 
'sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint'>


(And whatever used to be in x is now gone.) Of course most people just write

sage: R.<x> = ZZ[]

which defines the ring and assigns the generator in one step.

> Anyway, what I really don't like is when you make
>
> 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>

We should certainly raise a better error here (or accept it).
Automatic coercion is always a compromise between convenience and
surprise. For example, if we didn't have any coercions there than

sage: a = ZZ['x'].gen()
sage: a = ZZ['x'](2)
sage: b = SR(2)
sage: a
2
sage: b
2
sage: bool(a == b)
False    # hypothetically

would be especially confusing, especially if the context weren't so
clear (e.g. trying to debug something when a and b were generated by
completely different functions at completely different times.) Even if
one made an exception for "constants"

sage: a
x
sage: b
x
sage: bool(a == b)
False    # hypothetically

I think would still cause more confusion than the current behavior.

> Did I do something wrong, or is this a bug?  Because of the initial
> behavior, maybe I shouldn't expect to be able to do this.
>
> Thanks,
> - kcrisman
>
> --
> 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
>

-- 
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

Reply via email to