Sage: Ticket #24031: Coercion between Matrices over orders and over the number field
https://trac.sagemath.org/ticket/24031
<pre class="wiki">sage: L.<a> = CyclotomicField(5)
sage: OL= L.ring_of_integers()
sage: OL
Maximal Order in Cyclotomic Field of order 5 and degree 4
sage: M=Matrix(OL,2,[1-a,0,a,1+a])
sage: a.parent()
Cyclotomic Field of order 5 and degree 4
sage: a*M
---------------------------------------------------------------------------
....
TypeError: unsupported operand parent(s) for *: 'Cyclotomic Field of order 5 and degree 4' and 'Full MatrixSpace of 2 by 2 dense matrices over Maximal Order in Cyclotomic Field of order 5 and degree 4'
sage: M=Matrix(L,2,[1-a,0,a,1+a])
sage: a*M
[-a^2 + a 0]
[ a^2 a^2 + a]
</pre>en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/24031
Trac 1.1.6sbrandhorstFri, 13 Oct 2017 11:52:27 GMTtype, component, milestone changed
https://trac.sagemath.org/ticket/24031#comment:1
https://trac.sagemath.org/ticket/24031#comment:1
<ul>
<li><strong>type</strong>
changed from <em>PLEASE CHANGE</em> to <em>defect</em>
</li>
<li><strong>component</strong>
changed from <em>PLEASE CHANGE</em> to <em>coercion</em>
</li>
<li><strong>milestone</strong>
changed from <em>sage-8.1</em> to <em>sage-8.2</em>
</li>
</ul>
TicketsbrandhorstFri, 13 Oct 2017 11:54:11 GMT
https://trac.sagemath.org/ticket/24031#comment:2
https://trac.sagemath.org/ticket/24031#comment:2
<pre class="wiki">sage: M1=Matrix(L,2,[1-a,0,a,1+a])
sage: M2=Matrix(OL,2,[1-a,0,a,1+a])
sage: M1*M2
[a^2 - 2*a + 1 0]
[ 2*a a^2 + 2*a + 1]
</pre><p>
Works.
</p>
TicketsbrandhorstSat, 14 Oct 2017 10:02:16 GMT
https://trac.sagemath.org/ticket/24031#comment:3
https://trac.sagemath.org/ticket/24031#comment:3
<p>
The bug only occurs if calling a*M first, not if there is an M*a call:
</p>
<pre class="wiki">sage: L.<a> = CyclotomicField(5)
sage: OL= L.ring_of_integers()
sage: M=Matrix(OL,2,[1-a,0,a,1+a])
sage: a*M
---------------------------------------------------------------------------
...
TypeError: unsupported operand parent(s) for *: 'Cyclotomic Field of order 5 and degree 4' and 'Full MatrixSpace of 2 by 2 dense matrices over Maximal Order in Cyclotomic Field of order 5 and degree 4'
sage: M*a
---------------------------------------------------------------------------
....
TypeError: unsupported operand parent(s) for *: 'Full MatrixSpace of 2 by 2 dense matrices over Maximal Order in Cyclotomic Field of order 5 and degree 4' and 'Cyclotomic Field of order 5 and degree 4'
sage: exit
Exiting Sage (CPU time 0m0.56s, Wall time 0m24.20s).
[simon@Quadrator sage]$ ./sage
....
sage: L.<a> = CyclotomicField(5)
sage: OL= L.ring_of_integers()
sage: M=Matrix(OL,2,[1-a,0,a,1+a])
sage: M*a
[-a^2 + a 0]
[ a^2 a^2 + a]
sage: a*M
[-a^2 + a 0]
[ a^2 a^2 + a]
</pre>
TicketsbrandhorstSat, 14 Oct 2017 10:10:20 GMT
https://trac.sagemath.org/ticket/24031#comment:4
https://trac.sagemath.org/ticket/24031#comment:4
<p>
There we go...
</p>
<pre class="wiki">sage: L.<a> = CyclotomicField(5)
sage: OL= L.ring_of_integers()
sage: M=Matrix(OL,2,[1-a,0,a,1+a])
sage: coercion_model.explain(M,a)
Coercion on left operand via
Call morphism:
From: Full MatrixSpace of 2 by 2 dense matrices over Maximal Order in Cyclotomic Field of order 5 and degree 4
To: Full MatrixSpace of 2 by 2 dense matrices over Cyclotomic Field of order 5 and degree 4
Coercion on right operand via
Call morphism:
From: Cyclotomic Field of order 5 and degree 4
To: Full MatrixSpace of 2 by 2 dense matrices over Cyclotomic Field of order 5 and degree 4
Arithmetic performed after coercions.
Result lives in Full MatrixSpace of 2 by 2 dense matrices over Cyclotomic Field of order 5 and degree 4
Full MatrixSpace of 2 by 2 dense matrices over Cyclotomic Field of order 5 and degree 4
sage: coercion_model.explain(a,M)
Will try _r_action and _l_action
Unknown result parent.
</pre>
TicketsbrandhorstThu, 19 Oct 2017 07:18:17 GMTbranch set
https://trac.sagemath.org/ticket/24031#comment:5
https://trac.sagemath.org/ticket/24031#comment:5
<ul>
<li><strong>branch</strong>
set to <em>u/sbrandhorst/coercion_between_matrices_over_orders_and_over_the_number_field</em>
</li>
</ul>
TickettscrimMon, 23 Oct 2017 04:39:10 GMTcommit set
https://trac.sagemath.org/ticket/24031#comment:6
https://trac.sagemath.org/ticket/24031#comment:6
<ul>
<li><strong>commit</strong>
set to <em>a2e82e15a240f1e095c100d8cdb0f928373c6a68</em>
</li>
</ul>
<p>
Can you give me a brief synopsis of what you know, what you want, and where you're stuck?
</p>
<p>
From a quick look at your branch, you are doing conversion maps, which are not coercion maps and do not automatically get invoked with actions.
</p>
<p>
Also, I don't like the hack with the category on <code>ResidueLiftingMap</code>. I suspect you should implement a proper <code>Homset</code> parent.
</p>
TicketgitMon, 23 Oct 2017 06:06:19 GMTcommit changed
https://trac.sagemath.org/ticket/24031#comment:7
https://trac.sagemath.org/ticket/24031#comment:7
<ul>
<li><strong>commit</strong>
changed from <em>a2e82e15a240f1e095c100d8cdb0f928373c6a68</em> to <em>bc45dab36e11d82fbd1a150e60544b408b50f3fa</em>
</li>
</ul>
<p>
Branch pushed to git repo; I updated commit sha1. New commits:
</p>
TicketsbrandhorstMon, 23 Oct 2017 06:12:27 GMT
https://trac.sagemath.org/ticket/24031#comment:8
https://trac.sagemath.org/ticket/24031#comment:8
<p>
Huh. I guess that branch was an accident. I do not recall doing anything on this ticket. Looks quite unrelated too. So basically I did nothing.
</p>
<p>
Well I do know the difference between/coercion and conversion.
</p>
<p>
So I have to teach sage a conversion here. Namely to extend the base ring to the quotient field.
Where do I do that? Where is left / right multiplication even defined?
Where do I start?
</p>
TicketsbrandhorstThu, 31 May 2018 21:32:21 GMT
https://trac.sagemath.org/ticket/24031#comment:9
https://trac.sagemath.org/ticket/24031#comment:9
<p>
It seems the bug lies in the following example.
This is good
</p>
<pre class="wiki">sage: L.<a> = NumberField(x^3+x-1)
sage: OL = L.ring_of_integers()
sage: P = MatrixSpace(OL,1,1)
sage: from sage.categories.pushout import pushout
sage: pushout(P,L)
Full MatrixSpace of 1 by 1 dense matrices over Number Field in a with defining polynomial x^3 + x - 1
</pre><p>
and here comes the bug
</p>
<pre class="wiki">sage: pushout(L,P)
---------------------------------------------------------------------------
CoercionException Traceback (most recent call last)
<ipython-input-13-50299fa24306> in <module>()
----> 1 pushout(L,P)
/home/simon/sage_working/local/lib/python2.7/site-packages/sage/categories/pushout.pyc in pushout(R, S)
3992 # make sense, and in this case simply want to return that a pushout
3993 # couldn't be found.
-> 3994 raise CoercionException(ex)
3995
3996
CoercionException: base field and extension cannot have the same name 'a'
</pre><p>
If I swap the input elements in `sage.categories.pushout.pushout, then scalar multiplication works just fine. Thus I believe this is the underlying cause.
</p>
TicketsbrandhorstThu, 31 May 2018 21:57:47 GMT
https://trac.sagemath.org/ticket/24031#comment:10
https://trac.sagemath.org/ticket/24031#comment:10
<p>
It tries to apply the <code>AlgebraicExtensionFunctor</code> of L to itself and this crashes.
</p>
Ticket