I am looking for a package for dealing with "mappings" $f\colon A\to B$ where $A$ and $B$ are finite subsets of the set of all possible (inert) expressions.

I need operations like:

  • Computing $f(a)$ efficiently.
  • Converting $f$ from and to a list of rules.
  • Checking whether $f$ is injective (thus bijective).
  • Computing the inverse function if possible.
  • Listing the elements of $A$ and the set $f(A)$
  • Ensuring or enforcing that the elements of $A$ and/or $B$ match a certain pattern, e.g. _Integer.
  • Converting to and from a List for the case that $A$ is Range[1, n].
  • Efficient handling of the case that $B$ is a list of MachineReals (PackedArray...).

I want this for the following purposes (not exhaustive):

  • Abstract away different ways of representing variable-value assignments
  • Abstract away differences between lists, matrices, tensors, SparseArrays, PackedArrays which can be understood as a mapping position $\to$ number.

Is there something out there that does this or could be extended easily or would you sit down the few hours it takes and program this from scratch? Am I missing some available functionality that provides a nice representation and implementation of such mappings?

  • 2
    $\begingroup$ Association will do some of the tasks you list, and it is generally efficient. Map will compose two of them. PositionIndex will get you part way to an inverse function & injectivity (not sure about efficiency). Normal, Keys, Values make various lists (rules, domain, range, resp.). But no built-in pattern checking, AFAIK. And you would have to build your own data structure on top it, if you want to carry along the codomain. $\endgroup$ – Michael E2 Jul 29 '16 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.