MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg124375] Re: How to check whether an infinite set is closed under addition?
  • From: David Bevan <david.bevan at pb.com>
  • Date: Tue, 17 Jan 2012 06:00:40 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

It is only necessary to explicitly test that 2*a_i is in the set.

Assuming base is sorted, I think I'd use:

closedQ[base_] :=
  Module[{m = Most[base]},
    Complement[Select[Join[2 m, Plus @@@ Subsets[m, {2}]], # < Last[base] &],
      m] == {}]

(I've made some other optimisations / simplifications too.)

Replacing Join[] with DeleteDuplicates@Join[] may be faster, depending on the data.

David %^>


> 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]



  • Prev by Date: Re: plotting histograms with do loop
  • Next by Date: Re: Question about DeleteCases to remove list elements based on first character
  • 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?