Lattice Algebra: Problems with Flat and Orderless

*To*: mathgroup at smc.vnet.net*Subject*: [mg14896] Lattice Algebra: Problems with Flat and Orderless*From*: immtwg at brahe.gbar.dtu.dk (Torben Winther Graversen)*Date*: Wed, 25 Nov 1998 17:48:18 -0500*Organization*: UNI-C*Sender*: owner-wri-mathgroup at wolfram.com

Hi, I'm trying to implement an operator, called say "p", from a lattice algebra. It is thus commutative, associative, distributive and idempotent. I use the Flat and Orderless attributes to implement associativity and commutativity, but I also need to have a "top" element, called say "a", with this property: p[a, __] = a; so that e.g. "p[a,b,c]" gives just "a". This is obviously similar to multiplication with zero. If I implement this before I set the Flat and Orderless attributes it works: In[1]:= p[a, __] = a; In[2]:= p[a,b,c] Out[2]= a If I implement it after I set the attributes the pattern matcher will never let me reduce the expression to just "a" but rather "p[a]": In[3]:= ClearAll[p]; In[4]:= Attributes[p] = {Orderless, Flat}; In[5]:= p[a, __] = a; In[6]:= p[a,b,c] Out[6]= p[a] Question 1: How do I get around that? Adding a definition like p[x_]=x has the same problem, and an infinite recursion. The only way I have found to do it was to implement the rule before the attributes, and then set the attributes: In[7]:= ClearAll[p]; In[8]:= p[a, __] = a; In[9]:= Attributes[p] = {Orderless, Flat}; In[10]:= p[a,b,c] Out[10]= a But if I now repeat the definition of the rule, I get two seamingly identical rules for p: In[11]:= p[a, __] = a; In[12]:- ?p Global`p Attributes[p] = {Flat, Orderless} p[a, __] = a p[a, __] = a But it's still the original rule that is used: In[13]:= p[a,b,c] Out[13]= a Question 2: What exactly is going on here? -- Best regards, Torben Winther Graversen http://www.student.dtu.dk/~immtwg