ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 30 Oct 2012 19:19:00 -0500Where is the Inverse feature in FiniteSetMaps??http://ask.sagemath.org/question/9485/where-is-the-inverse-feature-in-finitesetmaps/Say I have defined a map `f` within the set of maps FiniteSetMaps....
It's great that I can do things like: `f.domain()`, `f.codomain()`, `f.image_set()`, `f.getimage()`.
But how do I take the inverse? Is that feature not present? Is it in the roadmap?
Thanks.Tue, 30 Oct 2012 10:59:19 -0500http://ask.sagemath.org/question/9485/where-is-the-inverse-feature-in-finitesetmaps/Answer by SLOtoSF for <p>Say I have defined a map <code>f</code> within the set of maps FiniteSetMaps....</p>
<p>It's great that I can do things like: <code>f.domain()</code>, <code>f.codomain()</code>, <code>f.image_set()</code>, <code>f.getimage()</code>.</p>
<p>But how do I take the inverse? Is that feature not present? Is it in the roadmap? </p>
<p>Thanks.</p>
http://ask.sagemath.org/question/9485/where-is-the-inverse-feature-in-finitesetmaps/?answer=14215#post-id-14215I am posting this as what I'm using in the meanwhile, but ideally it would be a method attribute of the class. The `fibers()` method is quite helpful here. It gives a dictionary of preimages of each element. Since we have singletons we just `pop()` and we know it's the inverse element.
Obviously we would want to check for bijectivity here...
> def inverse(func):
> dic = func.fibers()
> for i in func.codomain():
> dic[i] = set(dic[i]).pop()
> return FiniteSetMaps(func.codomain(),func.domain()).from_dict(dic)Tue, 30 Oct 2012 19:19:00 -0500http://ask.sagemath.org/question/9485/where-is-the-inverse-feature-in-finitesetmaps/?answer=14215#post-id-14215