MathGroup Archive 2004

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

Search the Archive

Re: use of orderless

  • To: mathgroup at smc.vnet.net
  • Subject: [mg52538] Re: use of orderless
  • From: Peter Pein <petsie at arcor.de>
  • Date: Wed, 1 Dec 2004 05:58:04 -0500 (EST)
  • References: <cohj5k$1nb$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

borges2003xx at yahoo.it wrote:

> i'm  trying to implement a  mark all binary lists in which three non
> overlapping sublists of the same  length(of length >= 3) a, b, and c ,
> where
> c  is the result of xor of a and b, in all way they can present
> (orderless).
> But it don't work . somebody can help me?
> 
> ZeroPad[x__] :=(*Takes Transpose after zero - padding*)Module[{l, y =
> Map[(#
> /. d_Integer :> IntegerDigits[d, 2]) &, {x}]}, l = Map[Length, y];
> Transpose[MapThread[Join[Table[0, {Max[l] - #1}], #2] &, {l, y}]]]
> 
> BitwiseXor[x__] := Flatten[Apply[Mod[Plus[##], 2] &, ZeroPad[x], {1}]]
> << DiscreteMath`Combinatorica`
> SetAttributes[mm, Orderless]
> mmQ[t1, t2, t3] := True /; (BitwiseXor[t1, t2] == t3) && (Length[t1]
> = 3) && (Length[t2] = 3) && (Length[t3] = 3)
> m[{x1___, a1__, x2___, a2__, x3___, a3__, x4___}] := {} /; mmQ[{a1}, {
> a2}, {a3}]
> m[l_] := l
> t1 = Strings[{0, 1}, 10];
> Rest[Union[Map[m, t1]]]
> 
> 
> Length[%]
> 1023
> 
Hi,

I'm sorry but from <<..Combinatrica on I don't understand your code. 
(What is mm?) How should Mathematica determine, which arguments of m[] 
should be assigned to which argument? I would prefer Lists as arguments.

The functions ZeroPad and BitwiseXor can be written easier:

In[1]:=
ZeroPad[x__] :=
   Module[{l, y = IntegerDigits[#, 2] & /@ {x}},
     l = Max[Length /@ y];
     Transpose[PadLeft[#, l] & /@ y]  ]
In[2]:=
   ZeroPad[1, 2, 3, 4, 5]
Out[2]=
   {{0, 0, 0, 1, 1},
    {0, 1, 1, 0, 0},
    {1, 0, 1, 0, 1}}
In[3]:=
   BitwiseXor[x__] :=
   PadLeft[IntegerDigits[BitXor[x], 2],
     If[# == 0, 1, 1 + Floor[Log[2, #]]] &[Max[x]]]
In[4]:=
   BitwiseXor[1, 2, 3, 4, 5]
Out[4]=
   {0, 0, 1}

-- 
Peter Pein
10245 Berlin


  • Prev by Date: Re: Re: canonical mathematical expression represenation?
  • Next by Date: Re: canonical mathematical expression represenation?
  • Previous by thread: Re: Re: canonical mathematical expression represenation?
  • Next by thread: Re: use of orderless