We help IT Professionals succeed at work.

# I need simple one-to-one function

on
Medium Priority
245 Views
Hi, I have a simple question in calculus:

Given a set of different integers A, each integer in range from 1 to 5000. It may be assumed that the set size won't be more than 50 (ie: |A|<=50).
I need a one-to-one function f that takes set A and returns an integer. (f: {..} --> R)
So for any A!=B => f(A)!=f(B) (!= stand for not equal). Of course, since A is a set, the order of integers doesn't matter, so A={1,2,3} identical to B={3,1,2}.

I'm sure there are a lot of simple functions that do the job, and functions with only primitive operators such as +,-,*,/ will be preffered.

Comment
Watch Question

## View Solutions Only

Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)

Commented:
Clarification for venkateshwarr:
There are a lot of different sets with specific size, for example if |A|=3 then there are more than 1.38^10 different sets. So I need a function which takes a set (which may be preseted as linked list of integers), checks list size and computes unique integer for the set according to numbers it contains. Then I store that computed integer, and if I get the same list again I can compare function output against already stored integers. So it saves time and space storage in time consuming applications.

Commented:
Comment for Dabas:
Your function is indeed gives one-to-one mapping, but it's not applicable since the numbers it produces are way beyond huge :)
Consider a set of 30 consequent integers: starting from 4950 to 4979. Even last computation 2^30 * 4979 is a huge number, not talking about the whole sum of previous 29.
I'm sorry, I've made a mistake when I told the function output need to be integer. It may (even should)  be double.

Commented:
GENERAL CLARIFICATION:
Function output may (should) be double. :)

f: {..} --> R means that functino takes a set of integers and returns a real number.
CERTIFIED EXPERT

Commented:
alex130:
Huge number indeed.
But if you have 30 consequent integers, then the amount of possible distinct permutations is equally huge!

Dabas
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)

Commented:
Thoughts: Mapping with hash function and giving each set a unique integer number is either inefficient, space wasting and would take years to compute. It will be better to map to real numbers, using mathematical formula, depending on the set length.
For example consider the following function, I'm not sure that it's one-to-one but it's defenitely a start :)

Suppose A={x1,x2,..,xn}
f(A)=(x1)^(0.n) + (x2)^(0.n) + ... + (xn)^(0.n)   (if |A|=5 then 0.n=0.5)
Of course 0.2=0.20 so lets asume that if number after decimal point is multiple
of ten, then it's converted to 0.nnn (so 0.30 will be 0.333). (When set size bound is 99 of course).
CERTIFIED EXPERT

Commented:
alex130:
My BA in Maths happened nearly 30 years ago... Can you please explain what the notation 0.n stands for?

Dabas

Commented:
to Dabas:
0.n stand for a double (Real) number.
for example if n=5 then it is simply 0.5 (1/2).
So if A={x1,x2,..,xn} then it has n elements (|A|=n) so i would raise each element in power of 0.n and sum results.
For example if A={2, 3004, 4443} then |A|=3 and
f(A)=2^0.3 + 3004^0.3 + 4443^0.3=24.70499967
So far I haven't neither proven that this function is one-to-one nor found a contradictory exmple. But anyway, even if this function is one-to-one it is too slow because it involves raising in power operation which is a very complex one, especially when raising in non integer power.
If you can come up with another one-to-one function which uses only primitive operations (+-,/*) it would be great! :)
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
if f(A) is truncated to a 64 bit float, it will not be one to one
Unlock the solution to this question.