Opened 9 years ago
Closed 3 years ago
#12778 closed defect (duplicate)
Incorrect coercion of matrix elements when from different rings
Reported by: | kcrisman | Owned by: | jason, was |
---|---|---|---|
Priority: | major | Milestone: | sage-duplicate/invalid/wontfix |
Component: | linear algebra | Keywords: | |
Cc: | jason, rbeezer | Merged in: | |
Authors: | Reviewers: | ||
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description (last modified by )
sage: M = matrix([[1,.9,1/5,x^2],[2,1.9,2/5,x^3],[3,2.9,3/5,x^4],[4,3.9,4/5,x^5]]) sage: type(M) <type 'sage.matrix.matrix_symbolic_dense.Matrix_symbolic_dense'> sage: M [ 1.00000000000000 0.900000000000000 0.200000000000000 x^2] [ 2 1.90000000000000 2/5 x^3] [ 3 2.90000000000000 3/5 x^4] [ 4 3.90000000000000 4/5 x^5]
Notice that the first row does something different to the entries than the others.
See this ask.sagemath.org question for background.
Change History (13)
comment:1 follow-up: ↓ 3 Changed 9 years ago by
comment:2 Changed 9 years ago by
- Description modified (diff)
comment:3 in reply to: ↑ 1 ; follow-up: ↓ 4 Changed 9 years ago by
Replying to jason:
Seems like your inputs and outputs are smashed together.
So this ticket is specifically about latexing a matrix?
It's not just about the TeX. The first row should read [1 0.9000etc 1/5 x^2]
, but the first and third elements aren't being treated the same way as they are in the other rows.
comment:4 in reply to: ↑ 3 Changed 9 years ago by
- Description modified (diff)
Seems like your inputs and outputs are smashed together.
Oops, yes, I changed it at the place I discovered this but not here.
So this ticket is specifically about latexing a matrix?
It's not just about the TeX. The first row should read
[1 0.9000etc 1/5 x^2]
, but the first and third elements aren't being treated the same way as they are in the other rows.
Correct.
comment:5 Changed 9 years ago by
Followup: we can push it back to Sequence.
sage: Sequence([1, 0.9, 1/5, x]) [1.00000000000000, 0.900000000000000, 0.200000000000000, x] sage: Sequence([1, 0.9, 1/5, x]).universe() Symbolic Ring sage: Sequence([1, 0.9, 1/5, x], SR) [1, 0.900000000000000, 1/5, x]
comment:6 Changed 9 years ago by
I figured we used the Sequence.universe
for this. Here's the problem in Sequence
.
for i in range(len(x)-1): try: x[i], x[i+1] = coerce.canonical_coercion(x[i],x[i+1])
This is fine for stepwise finding a universe, but what it does is try to coerce things one by one, instead of looking at all of them as a whole (which is probably slower, of course).
I say that there must be an easy way to fix the matrix code so that we don't call Sequence
immediately, but first use it to find a universe
, then make the new Sequence
as in your code. That would fix this ticket.
Then we could have a different ticket or sage-devel discussion on whether this Sequence
behavior is, in fact, a bug.
comment:7 Changed 9 years ago by
Got it. In sage.matrix.constructor.py:
entries = [] for v in args[0]: entries.extend(v)
is how the list is created. Then prepare
is used to make this into a list and base ring, and that is where Sequence
is used.
But the problem is that this means it takes the whole flattened list of entries in the matrix and does the step-by-step sequence construction.
We could just have it find the universe for the sequence and then make the sequence again. That could be a big slowdown, though. On the other hand, if someone is not specifying the ring ahead of time (this all happens only if elif len(args) == 1:
then they probably aren't as interested in speed, are they?
Thoughts?
comment:8 Changed 8 years ago by
- Milestone changed from sage-5.11 to sage-5.12
comment:9 Changed 7 years ago by
- Milestone changed from sage-6.1 to sage-6.2
comment:10 Changed 7 years ago by
- Milestone changed from sage-6.2 to sage-6.3
comment:11 Changed 7 years ago by
- Milestone changed from sage-6.3 to sage-6.4
comment:12 Changed 3 years ago by
- Description modified (diff)
comment:13 Changed 3 years ago by
- Milestone changed from sage-6.4 to sage-duplicate/invalid/wontfix
- Resolution set to duplicate
- Status changed from new to closed
Fixed in #24742 with doctest.
Seems like your inputs and outputs are smashed together.
So this ticket is specifically about latexing a matrix? Could you add that in the title to narrow down the scope?