1 | initial version |

Your question is very unclear but still let me try to speculate on what you are interested in. If you have a function **f** and a set of elements **X** and want to compute the elements **{f(x) : x in X}** as well as their preimages you can use dictionaries. Let me take the stupid example of the square function on Z/10Z.

```
sage: f = lambda x: x^2
sage: preimages = {}
sage: for x in Zmod(10):
....: y = f(x)
....: if y in preimages: preimages[y].append(x)
....: else: preimages[y] = {x]
sage: preimages
{0: [0], 1: [1, 9], 4: [2, 8], 5: [5], 6: [4, 6], 9: [3, 7]}
sage: preimages[4]
[2, 8]
```

2 | No.2 Revision |

Your question is very unclear but still let me try to speculate on what you are interested in. If you have a function **f** and a set of elements **X** and want to compute the ~~elements ~~set of images **{f(x) : x in X}** as well as their preimages you can use dictionaries. Let me take the stupid example of the square function on Z/10Z.

```
sage: f = lambda x: x^2
sage: preimages = {}
sage: for x in Zmod(10):
....: y = f(x)
....: if y in preimages: preimages[y].append(x)
....: else: preimages[y] = {x]
sage: preimages
{0: [0], 1: [1, 9], 4: [2, 8], 5: [5], 6: [4, 6], 9: [3, 7]}
sage: preimages[4]
[2, 8]
```

3 | No.3 Revision |

Your question is very unclear but still let me try to speculate on what you are interested in. If you have a function **f** and a set of elements **X** and want to compute the set of images **{f(x) : x in X}** as well as their preimages you can use dictionaries. Let me take the stupid example of the square function on Z/10Z.

```
sage: f = lambda x: x^2
sage: preimages = {}
sage: for x in Zmod(10):
....: y = f(x)
....: if y in preimages: preimages[y].append(x)
....: else: preimages[y] =
```~~{x]
~~[x]
sage: preimages
{0: [0], 1: [1, 9], 4: [2, 8], 5: [5], 6: [4, 6], 9: [3, 7]}
sage: preimages[4]
[2, 8]

4 | No.4 Revision |

Your question is very unclear but still let me try to speculate on what you are interested in. If you have a function **f** and a set of elements **X** and want to compute the set of images **{f(x) : x in X}** as well as their preimages you can use dictionaries. Let me take the stupid example of the square function on Z/10Z.

```
sage: f = lambda x: x^2
sage: preimages = {}
sage: for x in Zmod(10):
....: y = f(x)
....: if y in preimages: preimages[y].append(x)
....: else: preimages[y] = [x]
sage: preimages
{0: [0], 1: [1, 9], 4: [2, 8], 5: [5], 6: [4, 6], 9: [3, 7]}
sage: preimages[4]
[2, 8]
```

And if you want to access the set of images (which is in my example the squares in Z/10Z)

```
sage: preimages.keys()
[0, 1, 4, 5, 6, 9]
```

5 | No.5 Revision |

~~Your question ~~Some comments on your code.

1) There is ~~very unclear but still let me try to speculate on what ~~no need to import `numpy`

that you are ~~interested in. ~~not using.

2) You can simplify

```
x = vector(x)
x = x.row()
v = x.transpose()
b = x * A * v
```

into

```
x = vector(x)
b = x * A * x
```

Now to answer your question. If you ~~have a function ~~want to gather the images and **f** ~~a set of elements ~~the preimages you can use dictionaries. Let me **X** and want to compute the set of images **{f(x) : x in X}** as well as their ~~take the stupid ~~consider the simpler example of the square function on Z/10Z.

```
sage: f = lambda x: x^2
sage: preimages = {}
sage: for x in Zmod(10):
....: y = f(x)
....: if y in
```~~preimages: ~~preimages:
....: preimages[y].append(x)
....: ~~else: ~~else:
....: preimages[y] = [x]
sage: preimages
{0: [0], 1: [1, 9], 4: [2, 8], 5: [5], 6: [4, 6], 9: [3, 7]}
sage: preimages[4]
[2, 8]

And if you want to access the set of images (which is in my example the squares in Z/10Z)

```
sage: preimages.keys()
[0, 1, 4, 5, 6, 9]
```

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.