2

I want to know if all number pair equals each other that selected from a specified number set.

For example:

There is a set $A=\{5,3,6,2\}$ and to check the variable equalities requires to check the boolean result comparing each number to others. This method requires $C(5,2)=10$ comparisions. I need a short method to know this.

e.g:

$5*3*6*2=180$ and if $\sqrt[4]{180}$ is an integer number it can be said all are equal but this is not a correct way for all numbers.

Now I want to ask if there is a formulation such as multiply all values and check equality to a number or like it to make it easy?

Ali Tor
  • 180
  • Wait. what? If $A={2,4,8,16}$, then $2\times 4\times 16\times 32 = 4096$ and $\sqrt[4]{4096}$ is an integer, but it can't be said that $2=4=16=32$. – TonyK Apr 16 '16 at 17:04
  • If you read it correctly you can see I said "It is not a correct way for all numbers". – Ali Tor Apr 16 '16 at 17:05
  • How is it correct for any numbers? Do you mean that if the product is not a fourth power, then the numbers can't all be equal? This is true, but it's not what you said. – TonyK Apr 16 '16 at 17:06

2 Answers2

2

It's not clear (to me) whether you are asking if all the numbers are the same, or if there is at least one pair that's the same.

If you are looking for one pair:

You could compute the product of the differences and see if you get zero. That's just one numerical comparison, but lots more arithmetic. With five numbers it's 10 subtractions (and one multiplication) instead of 10 comparisons.

You could sort the list and then traverse it looking for an equal adjacent pair. With the right sorting algorithm that would require fewer comparisons than comparing every pair (for a long list). Here are some computer programs that do the job: https://stackoverflow.com/questions/4192724/algorithm-to-find-duplicate-in-an-array .

I doubt that either of these answers will satisfy your wish to "make it easy". I don't think there is any way to do that.

If you want to check whether all the numbers are the same you just have to compare each with the first one, as @Claude says in his answer.

Ethan Bolker
  • 95,224
  • 7
  • 108
  • 199
  • It can be used as a programming algorithym but I asked this question for a modelling program GAMS. In GAMS to check multiple variables equality is so hard. For 3 variables as x,y,z it requires to check x=y? x=z? y=z? and writing such algorithym needs so much working. That's why I ask a more mathematical way. – Ali Tor Apr 16 '16 at 17:02
2

Equality is reflexive ($ x = y \implies y = x $) and transitive ($ x = y \land y = z \implies x = z $) so you can compare all the other numbers against the first number, which for a set of $n$ numbers is $n-1$ operations.

Example for $n = 4$ with $(a, b, c, d)$:

$$ a = b \land a = c \land a = d \implies a = b = c = d $$

(Pedantic note: you have a tuple rather than a set, as a set by definition contains only distinct values.)

Claude
  • 5,647