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?
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] === {}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With