Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check whether an infinite set is closed under addition with a computer code?

Given k positive integer numbers a1 < a2 < a3 < ... < ak, and all integers greater than ak, we want to check whether the set A = {ai : i ∈ [1,k]} ∪ {n : n > ak, n ∈ ℕ } = {a1, a2, a3, ... , ak, ak+1, ak+2, ...} is closed under addition. This means that:

1 ≤ i ≤ k ai*bi ∈ A, for any non-negative integers bi.

For example, {2,4,6,7,8,....} is closed under addition.

Is there any easy way to do this? Any functions that we could use in Mathematica or Matlab?

like image 527
Osiris Xu Avatar asked Dec 01 '25 13:12

Osiris Xu


2 Answers

If the discontinuous portion less than k of the sets are not large I believe you can approach it directly like this:

a = {2, 4, 6};
Tr /@ Subsets[a, {2}];
TakeWhile[%, # < Last@a &];
Complement[%, a] === {}
like image 188
Mr.Wizard Avatar answered Dec 04 '25 03:12

Mr.Wizard


A banal observation: any sum having an operand >= a_k is a member of A, so you only need to be concerned with sums where both operands are from the set B = {a_1 .. a_(k-1)}. Naive solution in pseudocode:

for i from k-1 down to 1
  for j from i down to 1
    if (a_i + a_j < a_k) and (a_i + a_j is not in B) then
      return false
return true
like image 39
LaC Avatar answered Dec 04 '25 02:12

LaC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!