       Re: How to check whether an infinite set is closed under addition?

• To: mathgroup at smc.vnet.net
• Subject: [mg124314] Re: How to check whether an infinite set is closed under addition?
• From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
• Date: Mon, 16 Jan 2012 17:14:41 -0500 (EST)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• References: <201201150951.EAA19688@smc.vnet.net> <C9FCBB38-0E20-478B-97BC-BD57313E080F@mimuw.edu.pl> <C6EAFE27-EF70-42DA-8B1A-5250A05F6867@mimuw.edu.pl> <CANAzFigQi2hTXfdg-rvOB7dYjJKfoFPVZjjZ+BtH3tYdCbOnFw@mail.gmail.com> <CANAzFiikOHGAPvLUsZJFbJSWOsL8r6Kkc4WJNXYM-4WTnTvRfQ@mail.gmail.com> <CANAzFiiDRCGsMGRgMGKrJOkptnuTv-4TU2Uh9S7ravrkbg5CgA@mail.gmail.com> <CANAzFigvV5XVUF5mhcMZKmGUX=AiehHZC4JN9hYbyAGK5VFEPg@mail.gmail.com> <C1ACD522-A19D-4453-9FD5-9819ACA1FDB9@mimuw.edu.pl>

```On 16 Jan 2012, at 08:50, Andrzej Kozlowski wrote:

>
> On 16 Jan 2012, at 02:07, Mobius ReX wrote:
>
>> Sorry the condition of a set A to be closed under addition should be
>> `Sum[a_i*n_i ,{i,1,g}] =E2=88=88 A` for any non-negative integer `n_i`,  and a_i =E2=88=88 A.
>>
>> On Sun, Jan 15, 2012 at 5:04 PM, Mobius ReX <aoirex at gmail.com> wrote:
>>> Sorry the condition of a set A to be closed under addition should be
>>> `a_i*n + a_j*m =E2=88=88 A` for any positive integers `n` and `m` for any a_i =E2=88=88 A.
>
>
> Of course you are right. Essentially you  can use the previous code but you need to add to the base all the multiples of each element of the base that are less than the largest element of the base. In other words, I think the following should work:
>
> closedQ[base_List] :=
> Module[{b = Union[Flatten[Table[# i, {i, Last[base]/#}] & /@ base]]},
>   Complement[
>    Select[Total[Subsets[Most[b], {2}], {2}], # <= Last[base] &],
>    base] == {}]
>
>
> For example:
>
> closedQ[{2, 3, 5, 8}]
>
> False
>
> Andrzej
>
> closedQ[{2, 3, 4, 5, 6, 7, 8}]
>
> True
>
> I am again assuming that the base is sorted.
>
> Andrzej

Actually, this is not the most efficient way to do this. In fact it is better to combine two tests. The first checks if the base has the property that if a is an element then n a is also an element of the base (as long as n a is less than the last element of the base).

This can be checked as follows:

test1Q[base_] :=
Module[{b = Flatten[Table[# i, {i, Last[base]/#}] & /@ base]},
Complement[b, base] == {}]

The second test is the original one:

test2Q[base_List] :=
Complement[
Select[Total[Subsets[Most[base], {2}], {2}], # <= Last[base] &],
base] == {}

Now we define closedQ:

closedQ[base_List] := test1Q[base] && test2Q[base]

Again:

closedQ[{2, 3, 5, 8}]

False

closedQ[{2, 3, 4, 5, 6, 7, 8}]

True

This ought to be faster than my previous version since it does not perform the same checks twice (as the old version does).

Andrzej

```

• Prev by Date: Re: hatched regions, shading, and fills
• Next by Date: Re: How to simplify this code with variable number of
• Previous by thread: Re: How to check whether an infinite set is closed under addition?
• Next by thread: Re: How to check whether an infinite set is closed under addition?