Opened 10 years ago

Closed 10 years ago

#7007 closed defect (fixed)

[with patch, positive review] variables() method for polynomial rings returns the constant as well as the variable.

Reported by: jason Owned by: tbd
Priority: major Milestone: sage-4.2
Component: algebra Keywords:
Cc: Merged in: sage-4.2.alpha0
Authors: Mike Hansen Reviewers: Jason Grout
Report Upstream: Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description (last modified by jason)

[20:22] <jason-> here's something funny:
[20:22] <jason-> sage: QQ['t'].gen()
[20:22] <jason-> t
[20:22] <jason-> sage: RR['t'].gen()
[20:22] <jason-> 1.00000000000000*t
[20:24] <jason-> that means that I get a very funny variables() function:
[20:24] <jason-> sage: R.<t>=RR[]
[20:24] <jason-> sage: (t^2).variables()
[20:24] <jason-> (1.00000000000000*t,)

Attachments (1)

trac_7007.patch (21.5 KB) - added by mhansen 10 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 10 years ago by jason

  • Summary changed from generator of RR['t'] has a float attached to generator of RR['t'] and RDF['t'] has a float attached

Same problem:

sage: RDF['t'].gen(0)
1.0*t

comment:2 Changed 10 years ago by jason

  • Summary changed from generator of RR['t'] and RDF['t'] has a float attached to variables() method for polynomial rings returns the constant as well as the variable.

comment:3 Changed 10 years ago by jason

  • Description modified (diff)

comment:4 Changed 10 years ago by kcrisman

This is nice, but it's a little troubling that it returns things looking "exact" that aren't actually exact. Are there any Sage defaults for this?

comment:5 Changed 10 years ago by kcrisman

Maybe the more natural fix to this is to change symbolic/expression_conversions.py in PolynomialConverter?.init , where instead of checking repr(v) one would check ring.base_ring()(1)*v, I think. For this to work, there needs to be consistency in the representations of these, of course.

However, as it turns out, somebody (Pynac?) simplifies like this patch does already, but for the symbolic ring, though only for the case with Ring(1), not Ring(2) or others.

sage: RR(1)*x
x
sage: RR(2)*x
2.000..000*x

Reverting that to at least printing 1.0 (and cutting off the extra zeros, which happens for RDF) seems to be the best strategy. Then one could change PolynomialConverter?. But I don't know how to fix Pynac representations of this kind.

Incidentally, note that #5755 probably will be fixed by this ticket, one way or another (the current patch fixes it, though as noted above not in a manner to my liking).

Changed 10 years ago by mhansen

comment:6 Changed 10 years ago by jason

  • Summary changed from variables() method for polynomial rings returns the constant as well as the variable. to [with patch, positive review] variables() method for polynomial rings returns the constant as well as the variable.

After talking on IRC, I think this patch is okay. In Sage, there is no such thing as the pure variable in this case; the variable is the polynomial 1.0000000*x. As such, I think it's fine to extend the printing conveniences to 1.0000*x that are currently given to 1*x.

Plus this fixes at least two issues (here and #5755).

comment:7 Changed 10 years ago by mhansen

  • Authors set to Mike Hansen
  • Merged in set to sage-4.2.alpha0
  • Resolution set to fixed
  • Reviewers set to Jason Grout
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.