Sage: Ticket #5201: make solve understand matrix equations
https://trac.sagemath.org/ticket/5201
<p>
I think it would be a great thing if solve could recognize matrices and that two matrices are equal if each entry is equal. I believe MMA does this (but it's easier there; matrices are nothing more than nested lists). It'd certainly make certain things I do more natural if I could do:
</p>
<p>
<code>solve(matrixA==matrixB)</code>
</p>
<p>
and that was equivalent to:
</p>
<p>
<code>solve([i==j for i,j in zip(matrixA.list(), matrixB.list())]) </code>
</p>
<p>
Okay, so now that I've written my piece, I suppose the next step is to open a trac ticket, write a patch to implement it, and post it for review :).
</p>
en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/5201
Trac 1.1.6mabshoffSat, 07 Feb 2009 19:23:11 GMTmilestone changed
https://trac.sagemath.org/ticket/5201#comment:1
https://trac.sagemath.org/ticket/5201#comment:1
<ul>
<li><strong>milestone</strong>
changed from <em>sage-3.4</em> to <em>sage-3.4.1</em>
</li>
</ul>
<p>
Which part of no non-ReST tickets against 3.4 is hard to understand? :p
</p>
<p>
Cheers,
</p>
<p>
Michael
</p>
TicketjasonSat, 07 Feb 2009 19:29:47 GMT
https://trac.sagemath.org/ticket/5201#comment:2
https://trac.sagemath.org/ticket/5201#comment:2
<p>
argh! I looked at the list and thought "the first item is the ReST transition, so I have to pick the second item". Apparently I was thinking that the next release was already out and 3.3 was the ReST transition.
</p>
TicketjasonWed, 26 May 2010 15:15:32 GMTkeywords, upstream set
https://trac.sagemath.org/ticket/5201#comment:3
https://trac.sagemath.org/ticket/5201#comment:3
<ul>
<li><strong>keywords</strong>
<em>beginner</em> added
</li>
<li><strong>upstream</strong>
set to <em>N/A</em>
</li>
</ul>
TicketryanThu, 14 Apr 2011 03:37:39 GMT
https://trac.sagemath.org/ticket/5201#comment:4
https://trac.sagemath.org/ticket/5201#comment:4
<p>
Could this be accomplished by overriding the comparison operator for the matrix class?
</p>
<p>
for example
</p>
<div class="wiki-code"><div class="code"><pre><span class="k">def</span> <span class="nf">__richcmp__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> other_matrix<span class="p">,</span> cmptype<span class="p">):</span>
<span class="k">if</span> cmptype <span class="o">==</span> <span class="mi">2</span><span class="p">:</span> <span class="c">#this is the '==' operator</span>
<span class="k">if</span> is_Matrix<span class="p">(</span>other_matrix<span class="p">):</span>
<span class="k">if</span> <span class="bp">False</span> <span class="ow">in</span> <span class="p">[</span>i<span class="o">==</span>j <span class="k">for</span> i<span class="p">,</span>j <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span>list<span class="p">(),</span> other_matrix<span class="o">.</span>list<span class="p">())]:</span>
<span class="k">return</span> <span class="bp">False</span>
<span class="k">else</span><span class="p">:</span> <span class="k">return</span> <span class="bp">True</span>
</pre></div></div><p>
I'm just not sure where the 'matrix class' is. This would allow comparisons like
</p>
<pre class="wiki">sage: matrixA == matrixB
True
</pre>
TicketjasonThu, 14 Apr 2011 03:50:19 GMTkeywords deleted
https://trac.sagemath.org/ticket/5201#comment:5
https://trac.sagemath.org/ticket/5201#comment:5
<ul>
<li><strong>keywords</strong>
<em>beginner</em> removed
</li>
</ul>
<p>
You bring up a good point, and make me doubt whether the feature request is even feasible. Certainly it's probably not a beginner ticket after all. The problem is that we already have an == operator:
</p>
<pre class="wiki">sage: a=matrix(SR,2,[x,x^2,x+1,x+4])
sage: b=matrix(SR,2,[4,3,2,1])
sage: a==b
False
</pre><p>
That means that all solve will see is False. Instead, we want something like:
</p>
<pre class="wiki">
sage: SR(a)==SR(b)
([ x x^2]
[x + 1 x + 4]) == ([4 3]
[2 1])
</pre><p>
(i.e., we want the == in the solve to construct an equation, which it does for symbolic objects. One of the issues at heart here is that a symbolic object wrapping a Sage matrix is different from a Sage matrix containing symbolic objects.
</p>
<p>
So I'm going to take off beginner status for this ticket here. It would still be nice if solve(SR(a)==SR(b)) worked in the above example.
</p>
TicketjdemeyerTue, 13 Aug 2013 15:35:53 GMTmilestone changed
https://trac.sagemath.org/ticket/5201#comment:6
https://trac.sagemath.org/ticket/5201#comment:6
<ul>
<li><strong>milestone</strong>
changed from <em>sage-5.11</em> to <em>sage-5.12</em>
</li>
</ul>
Ticketvbraun_spamThu, 30 Jan 2014 21:20:52 GMTmilestone changed
https://trac.sagemath.org/ticket/5201#comment:7
https://trac.sagemath.org/ticket/5201#comment:7
<ul>
<li><strong>milestone</strong>
changed from <em>sage-6.1</em> to <em>sage-6.2</em>
</li>
</ul>
Ticketvbraun_spamTue, 06 May 2014 15:20:58 GMTmilestone changed
https://trac.sagemath.org/ticket/5201#comment:8
https://trac.sagemath.org/ticket/5201#comment:8
<ul>
<li><strong>milestone</strong>
changed from <em>sage-6.2</em> to <em>sage-6.3</em>
</li>
</ul>
Ticketvbraun_spamSun, 10 Aug 2014 16:51:03 GMTmilestone changed
https://trac.sagemath.org/ticket/5201#comment:9
https://trac.sagemath.org/ticket/5201#comment:9
<ul>
<li><strong>milestone</strong>
changed from <em>sage-6.3</em> to <em>sage-6.4</em>
</li>
</ul>
TicketrwsTue, 24 Feb 2015 09:07:56 GMTmilestone changed
https://trac.sagemath.org/ticket/5201#comment:10
https://trac.sagemath.org/ticket/5201#comment:10
<ul>
<li><strong>milestone</strong>
changed from <em>sage-6.4</em> to <em>sage-wishlist</em>
</li>
</ul>
Ticket