Sage: Ticket #22707: Remove CombinatorialFreeModule.__contains__
https://trac.sagemath.org/ticket/22707
<p>
<code>Parent.__contains__</code> is implemented so that <code>x in R</code> is basically the same as <code>R(x)==x</code>.
</p>
<p>
CombinatorialFreeModule overrides it, so that it becomes <code>x.parent()==R</code>. That notion of containment is totally against Sage's coercion framework and should finally (after 9 years) be removed.
</p>
en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/22707
Trac 1.1.6SimonKingWed, 29 Mar 2017 14:07:36 GMTbranch set
https://trac.sagemath.org/ticket/22707#comment:1
https://trac.sagemath.org/ticket/22707#comment:1
<ul>
<li><strong>branch</strong>
set to <em>u/SimonKing/Remove_custom_contains</em>
</li>
</ul>
TicketSimonKingWed, 29 Mar 2017 14:09:17 GMTstatus changed; commit, author set
https://trac.sagemath.org/ticket/22707#comment:2
https://trac.sagemath.org/ticket/22707#comment:2
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>needs_review</em>
</li>
<li><strong>commit</strong>
set to <em>ba5f963354c69109a6c5abaaaf5dfd1ecbcbafa8</em>
</li>
<li><strong>author</strong>
set to <em>Simon King</em>
</li>
</ul>
<p>
I didn't run the tests yet...
</p>
<hr />
<p>
New commits:
</p>
<table class="wiki">
<tr><td><a class="ext-link" href="https://git.sagemath.org/sage.git/commit?id=ba5f963354c69109a6c5abaaaf5dfd1ecbcbafa8"><span class="icon"></span>ba5f963</a></td><td><code>Remove custom containment test in CombinatorialFreeModule</code>
</td></tr></table>
TickettscrimWed, 29 Mar 2017 15:19:39 GMTcc set
https://trac.sagemath.org/ticket/22707#comment:3
https://trac.sagemath.org/ticket/22707#comment:3
<ul>
<li><strong>cc</strong>
<em>sage-combinat</em> <em>nthiery</em> added
</li>
</ul>
<p>
This broadens the result of <code>__contains__</code> by allowing things that <em>convert</em> into the CFM, so it is a behavior change. I'm not against this change, and I doubt anyone is actually using this distinction, but it is something to be aware of.
</p>
<pre class="wiki">sage: F.<x,y> = FreeAlgebra(QQ)
sage: R.<x,y> = FreeAlgebra(ZZ)
sage: elt = 2*x + y
sage: elt in F
False
sage: elt in R
True
sage: F(elt) == elt
True
sage: F(elt) in R
False
</pre><p>
Also, in the cases of returning <code>False</code>, it is likely a slower check.
</p>
TicketnthieryWed, 29 Mar 2017 16:32:02 GMT
https://trac.sagemath.org/ticket/22707#comment:4
https://trac.sagemath.org/ticket/22707#comment:4
<p>
Hi Simon, Travis,
</p>
<p>
Hmm, the behaviour implemented in <code>Parent</code> is tricky and questionable.
Generally speaking, anything involving mathematical equality is
intrinsically a potential can of worm; see e.g.
<a class="ext-link" href="https://wiki.sagemath.org/EqualityCoercion"><span class="icon"></span>https://wiki.sagemath.org/EqualityCoercion</a>.
</p>
<p>
Let's take an example:
</p>
<pre class="wiki">sage: S = SymmetricFunctions(QQ)
sage: S.inject_shorthands()
sage: f = s[3]; f
s[3]
sage: f.parent()
Symmetric Functions over Rational Field in the Schur basis
sage: e
Symmetric Functions over Rational Field in the elementary basis
sage: f in e
False
sage: e(s[3])
e[1, 1, 1] - 2*e[2, 1] + e[3]
</pre><p>
As a user, I might not expect <code>s</code> to be in <code>e</code>: it's certainly a
symmetric function, but not one expressed in the e basis. There is a
canonical coercion between the two, but it is nowhere trivial.
</p>
<p>
Well, maybe I just have to accept that there is no perfect answer and
consistency should just be the priority. I don't remember: did we
specify explicitly somewhere what the semantic of contains should be,
and how it should behave w.r.t. coercion?
</p>
<p>
In summary, like for equality, I am not comfortable with having
coercion involved, but maybe that's ok. On the other hand conversion
certainly should not be involved, as there is nothing canonical with
them. Maybe that's more or less taken care of by the equality test of
R(x)=x.
</p>
TicketchapotonSun, 11 Mar 2018 17:15:11 GMTstatus, milestone changed
https://trac.sagemath.org/ticket/22707#comment:5
https://trac.sagemath.org/ticket/22707#comment:5
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>needs_work</em>
</li>
<li><strong>milestone</strong>
changed from <em>sage-8.0</em> to <em>sage-8.2</em>
</li>
</ul>
<p>
does not apply
</p>
Ticket