       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:= p[a, __] = a;

In:= p[a,b,c]
Out= 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:= ClearAll[p];

In:= Attributes[p] = {Orderless, Flat};

In:= p[a, __] = a;

In:= p[a,b,c]
Out= 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:= ClearAll[p];

In:= p[a, __] = a;

In:= Attributes[p] = {Orderless, Flat};

In:= p[a,b,c]
Out= a

But if I now repeat the definition of the rule, I get two seamingly
identical rules for p:

In:= p[a, __] = a;

In:- ?p

Global`p

Attributes[p] = {Flat, Orderless}

p[a, __] = a

p[a, __] = a

But it's still the original rule that is used:

In:= p[a,b,c]
Out= a

Question 2:
What exactly is going on here?

--
Best regards,

Torben Winther Graversen
http://www.student.dtu.dk/~immtwg

```

• Prev by Date: Re: tag on input form
• Next by Date: Plot Image Size
• Previous by thread: Re: writing mathematica list to a file
• Next by thread: Plot Image Size