ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 31 Oct 2012 01:19:00 +0100Where is the Inverse feature in FiniteSetMaps??https://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 16:59:19 +0100https://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>
https://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)Wed, 31 Oct 2012 01:19:00 +0100https://ask.sagemath.org/question/9485/where-is-the-inverse-feature-in-finitesetmaps/?answer=14215#post-id-14215