Algorithm where input is different but output is the same

297 Views Asked by At

I have a programming background and am working on an algorithm where I may not know the technical terms. Thanks for bearing with me as I try to explain what I'm looking for. I was wondering if there is any kind of algorithm or name for one where two different input can have the same output, but when reversed, I can tell which input I used. I understand the relationship of "many to one" and "one to many". But I am not sure that's the end of my research. I am looking for an algorithm (if it exists) where I can do something like this:

7 ↤<algorithm>⟼ 3
6 ↤<algorithm>⟼ 3

So; an algorithm that is equals 3 when 7 and 6 are input, but I would be able to distinguish if 7 or 6 is used if I reverse the algorithm. I can only use outside variables if it is cyclic or a pattern, such as 0,1,0,1... or 1,2,3,4,1,2,3,4... etc. But I will never know if I am to use a 7 or a 6 (for example) as input until they are ready to be operated on to get 3. I.E. there is no pattern to know when they appear. They are random.

Thanks in advance for any pointers.

2

There are 2 best solutions below

0
On BEST ANSWER

Consider you give some input in the algorithm and I get the output $3$. How should I know if your input was $6$ or $7$? It is not possible without further information.

If you need a reverse function/algorithm to $f:\mathbb N\to\mathbb N$ which is not necessarily injective, you can consider the modified function/algorithm $\tilde f:\mathbb N\to\mathbb N\times \mathbb N$ defined by $\tilde f(x):= (x,f(x))$. So, if $(x,y)\in \tilde f(\mathbb N)$ is some output, then you know that $x$ was the input and further $y=f(x)$.

In your case, the modified algorithm gives $\tilde f(6)=(6,3)$ and $\tilde f(7)=(7,3)$. If you get the output $(6,3)$, then you know that $3$ was produced by the input $6$ and not by $7$.

0
On

Not sure to understand your question but if you are asking for a way to tell what the input was for the given output, it is a clear: no way. This information is lost forever.