Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #7849 > unrolled thread

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

Started byRex <aoirex@gmail.com>
First post2012-01-15 09:53 +0000
Last post2012-01-17 08:30 +0000
Articles 3 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  How to check whether an infinite set is closed under addition? Rex <aoirex@gmail.com> - 2012-01-15 09:53 +0000
    Re: How to check whether an infinite set is closed under addition? "Dr. Wolfgang Hintze" <weh@snafu.de> - 2012-01-16 11:48 +0000
      Re: How to check whether an infinite set is closed under addition? "Dr. Wolfgang Hintze" <weh@snafu.de> - 2012-01-17 08:30 +0000

#7849 — How to check whether an infinite set is closed under addition?

FromRex <aoirex@gmail.com>
Date2012-01-15 09:53 +0000
SubjectHow to check whether an infinite set is closed under addition?
Message-ID<jeu7ma$j85$1@smc.vnet.net>
Given k positive numbers a_1<a_2<a_3<...<a_k, and all integers greater
than a_k, we want to check whether this set {a_1, a_2, a_3,...a_k, a_k
+ 1, a_k+2, ......} is closed under addition.

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

Your help will be greatly appreciated.

[toc] | [next] | [standalone]


#7864

From"Dr. Wolfgang Hintze" <weh@snafu.de>
Date2012-01-16 11:48 +0000
Message-ID<jf12qj$5fb$1@smc.vnet.net>
In reply to#7849
"Rex" <aoirex@gmail.com> schrieb im Newsbeitrag 
news:jeu7ma$j85$1@smc.vnet.net...
> Given k positive numbers a_1<a_2<a_3<...<a_k, and all integers 
> greater
> than a_k, we want to check whether this set {a_1, a_2, a_3,...a_k, 
> a_k
> + 1, a_k+2, ......} is closed under addition.
>
> Is there any easy way to do this? any functions that we could use in
> Mathematica?
>
> Your help will be greatly appreciated.
>
>

You could proceed as follows:

(* create some sample data for the set *)
m = Union[Array[Random[Integer, {1, 5}] & , 5]]
Out[44]=
{1, 2, 3, 4, 5}

(* Form all subsets with mor than 1 element *)
ms = Subsets[m, {2, Length[m]}]
Out[45]=
{{1, 2}, {1, 3}, {1, 4}, {1, 5}, {2, 3}, {2, 4},
{2, 5}, {3, 4}, {3, 5}, {4, 5}, {1, 2, 3},
{1, 2, 4}, {1, 2, 5}, {1, 3, 4}, {1, 3, 5},
{1, 4, 5}, {2, 3, 4}, {2, 3, 5}, {2, 4, 5},
{3, 4, 5}, {1, 2, 3, 4}, {1, 2, 3, 5},
{1, 2, 4, 5}, {1, 3, 4, 5}, {2, 3, 4, 5},
{1, 2, 3, 4, 5}}

(* compute all sums *)
mp = (Plus @@ #1 & ) /@ ms
Out[46]=
{3, 4, 5, 6, 5, 6, 7, 7, 8, 9, 6, 7, 8, 8, 9, 10, 9,
10, 11, 12, 10, 11, 12, 13, 14, 15}

(* find maximum of m in order to discard elements > maximum of m *)
mx = Max[m]
Out[47]=
5

(* find all elements of m, the set of all sums, less than mx *)
mp1 = Select[mp, #1 < mx & ]
Out[48]=
{3, 4}

(* the intersection shows if the set m is closed under addition *)
Intersection[mp1, m]
Out[56]=
{3, 4}

(* as a result, thwe logical variable clsd indicates the closedness of 
the set *)
clsd = mp1 == Intersection[mp1, m]
Out[55]=
True

Regards,
Wolfgang 

[toc] | [prev] | [next] | [standalone]


#7899

From"Dr. Wolfgang Hintze" <weh@snafu.de>
Date2012-01-17 08:30 +0000
Message-ID<jf3bih$n7t$1@smc.vnet.net>
In reply to#7864
Sorry, while I think the code is correct my choice for the sample data 
was no good, of course.
Please vary the parameters in the line

> m = Union[Array[Random[Integer, {1, 5}] & , 5]]

from 5 to

m = Union[Array[Random[Integer, {1, a}] & , b]]

with a > b to generate non-trivial sets with gaps.

Best regards,
Wolfgang

"Dr. Wolfgang Hintze" <weh@snafu.de> schrieb im Newsbeitrag 
news:jf12qj$5fb$1@smc.vnet.net...
>
> "Rex" <aoirex@gmail.com> schrieb im Newsbeitrag
> news:jeu7ma$j85$1@smc.vnet.net...
>> Given k positive numbers a_1<a_2<a_3<...<a_k, and all integers
>> greater
>> than a_k, we want to check whether this set {a_1, a_2, a_3,...a_k,
>> a_k
>> + 1, a_k+2, ......} is closed under addition.
>>
>> Is there any easy way to do this? any functions that we could use in
>> Mathematica?
>>
>> Your help will be greatly appreciated.
>>
>>
>
> You could proceed as follows:
>
> (* create some sample data for the set *)
> m = Union[Array[Random[Integer, {1, 5}] & , 5]]
> Out[44]=
> {1, 2, 3, 4, 5}
>
> (* Form all subsets with mor than 1 element *)
> ms = Subsets[m, {2, Length[m]}]
> Out[45]=
> {{1, 2}, {1, 3}, {1, 4}, {1, 5}, {2, 3}, {2, 4},
> {2, 5}, {3, 4}, {3, 5}, {4, 5}, {1, 2, 3},
> {1, 2, 4}, {1, 2, 5}, {1, 3, 4}, {1, 3, 5},
> {1, 4, 5}, {2, 3, 4}, {2, 3, 5}, {2, 4, 5},
> {3, 4, 5}, {1, 2, 3, 4}, {1, 2, 3, 5},
> {1, 2, 4, 5}, {1, 3, 4, 5}, {2, 3, 4, 5},
> {1, 2, 3, 4, 5}}
>
> (* compute all sums *)
> mp = (Plus @@ #1 & ) /@ ms
> Out[46]=
> {3, 4, 5, 6, 5, 6, 7, 7, 8, 9, 6, 7, 8, 8, 9, 10, 9,
> 10, 11, 12, 10, 11, 12, 13, 14, 15}
>
> (* find maximum of m in order to discard elements > maximum of m *)
> mx = Max[m]
> Out[47]=
> 5
>
> (* find all elements of m, the set of all sums, less than mx *)
> mp1 = Select[mp, #1 < mx & ]
> Out[48]=
> {3, 4}
>
> (* the intersection shows if the set m is closed under addition *)
> Intersection[mp1, m]
> Out[56]=
> {3, 4}
>
> (* as a result, thwe logical variable clsd indicates the closedness 
> of
> the set *)
> clsd = mp1 == Intersection[mp1, m]
> Out[55]=
> True
>
> Regards,
> Wolfgang
>
> 

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web