Equational attributes are a means of declaring certain kinds of equational axioms in a way that allows Maude to use these equations efficiently in a built-in way. Currently Maude supports the following equational attributes:
An operator can be declared with several of these attributes, which may appear in any order in the attribute declaration. However, these attributes are only allowed for binary operators satisfying the following requirements:
Furthermore, we have the following additional requirements:
Semantically, declaring a set of equational attributes for an operator is equivalent to declaring the corresponding equations for the operator. Operationally, using equational attributes to declare such equations avoids termination problems and leads to much more efficient evaluation of terms containing such an operator. In fact, the effect of declaring equational attributes is to compute with equivalence classes modulo such equations. This, besides being very expressive, avoids what otherwise would be insoluble termination problems. For example, if a commutativity equation like x + y = y + x is declared as an ordinary equation, then it will easily produce looping, nonterminating simplifications. If it is instead declared with an equational attribute comm, this looping behavior does not happen.
In our numbers example we can add a constant nil for the empty sequence and refine the declaration of sequence concatenation so that concatenation is associative with identity nil.
op nil : -> NatSeq . op __ : NatSeq NatSeq -> NatSeq [assoc id: nil] .
As another example, we can form lists of Booleans as a supersort BList of Bool in an extension of the BOOL module (see Section 7.1) with a ``cons'' operator _._ having nil as a right identity:
sort BList . subsort Bool < BList . op nil : -> BList . op _._ : Bool BList -> BList [right id: nil] .
Note that, when equational attributes are declared, equational simplification using the other equations in the module does not take place at the purely syntactic level of replacing syntactic equals by equals, but is understood modulo the equational attributes. Therefore, the proper understanding of the notions of Church-Rosser and terminating equations, and of canonical forms, is now modulo the equational attributes that have been declared. We discuss matching and equational simplification modulo axioms in Section 4.8.
For example, by declaring the addition operation on natural numbers modulo 3 as commutative,
op _+_ : Nat3 Nat3 -> Nat3 [comm] .
it is enough to have the following equations to define its behavior on all possible combinations of arguments:
vars N3 : Nat3 . eq N3 + 0 = N3 . eq 1 + 1 = 2 . eq 1 + 2 = 0 . eq 2 + 2 = 1 .
The equations
eq 0 + N3 = N3 . eq 2 + 1 = 0 .
are not needed, because they are subsumed by the first and third equations above,
due to commutativity of _+_.
Notice that membership axioms and matching modulo associativity can interact in undesirable ways, as explained in Section 13.2.8.